DEV Community

Cover image for Async vs Await, isn’t This Just Synchronous?
Arka Chakraborty
Arka Chakraborty

Posted on

Async vs Await, isn’t This Just Synchronous?

📌Intro

If awaitpauses execution… doesn’t that make it synchronous again? This is the #1 async misconception.


đź§ Context

  • awaitlooks synchronous but isn’t.
  • It pauses only the current async function, without blocking the event loop.

Examples:

async function main() { console.log("Before"); await new Promise(res => setTimeout(res, 1000)); console.log("After"); } main(); console.log("Outside"); // Output: // Before // Outside // After 
Enter fullscreen mode Exit fullscreen mode

Arrow version:

const main = async () => { console.log("Start"); await new Promise(res => setTimeout(res, 1000)); console.log("Done"); }; main(); 
Enter fullscreen mode Exit fullscreen mode

đź’ˇReal-Life Example:

Your UI doesn’t freeze while waiting for a network call.
E.g., while checking login, users can still scroll, click, or type.


JavaScript is single-threaded, but async/await lets you write non-blocking code that looks clean.

Top comments (0)