JavaScript Interview Question #72
What is the difference between synchronous and asynchronous JavaScript?
DOM, Events & Event Loop Fundamentals Mid-Level Intermediate
Quick Interview Answer
Synchronous code executes in sequence, and a long-running operation can prevent later work on the same thread from progressing. Asynchronous APIs allow work such as timers, network requests, or other external operations to complete later while JavaScript can continue processing other tasks.
Detailed Explanation
Synchronous code executes in sequence, and a long-running operation can prevent later work on the same thread from progressing. Asynchronous APIs allow work such as timers, network requests, or other external operations to complete later while JavaScript can continue processing other tasks.
JavaScript's concurrency model relies on the runtime environment, task queues, and event loop. Asynchronous does not necessarily mean that ordinary JavaScript statements themselves run simultaneously on multiple threads.
Code Example
console.log("A");
setTimeout(() => {
console.log("C");
}, 0);
console.log("B");
// A
// B
// C