Professional Documents
Culture Documents
News App
News App
console.log('one')
console.log('two')
console.log('three')// Output: one two three
ASYNC IN JS
However, this simplicity comes with a disadvantage when dealing with time-
consuming operations, such as delays or network requests, as the entire execution
is blocked until the operation is completed.
function printDelay() {
console.log('Phew!')
}
delay(5000)
printDelay()
ASYNC IN JS
In the example above, the code requires a delay of 5 seconds before printing a
greeting message to the console. However, the delay function is synchronous,
which means that the execution of the entire code is blocked for 5 seconds until
the delay function is completed. During this time, the JavaScript engine cannot
execute any other code, making the application unresponsive.
They always return a Promise. Even if we didn't explicitly specify it, they would still
return a Promise when called.
BUNDLING ASYNC/AWAIT
Within asynchronous functions, you can call other asynchronous functions with the help of the await keyword.