Course contents
- 01Variables
- 02Primitive Data Types
- 03Operators
- 04Conditionals
- 05Arrays
- 06Array methods and properties
- 07Objects
- 08Functions
- 09Callbacks
- 10Arrow functions
- 11Promises
- 12Async and await
- 13Loops
- 14DOM Manipulation
- 15Syntax parser
- 16Execution context and hoisting
- 17Call stack
- 18WebAPI and setTimeout
- 19Closures
- 20Function Constructors and Prototypes
- 21By value vs by reference
Async and await
An async function is syntactic sugar over promises, the code looks much cleaner. Its asynchronous code looks and behaves a little more like synchronous code. With async/await, you really wait for one promise to resolve before moving to the next line.




We can access the await keyword in a function if it has the keyword async before it. Any async function returns a promise implicitly, and the resolve value of the promise will be whatever you return from the function, which is “data” in our case.
console.log(awaitcallPromise()) basically means: wait until the callPromise promise has resolved, then console.log gets called that prints the value that is returned. It pauses the execution of your method until the value from the promise is available. If you don’t await, you’ll get the promise instead of the value you expect!
Async/await and promises are not logically equivalent! The async/await loads the results in sequence, while the promise example loads in parallel. However, async/await and promises are the same thing under the hood.
References and further reading
- MDN: async functionHow async functions always return a promise.
- MDN: awaitPause an async function until a promise settles.