What is the difference between synchronous and asynchronous JavaScript?

Answer

Synchronous code executes line by line — each line waits for the previous to complete before running. The call stack is blocked during this time. For quick operations this is fine, but for slow operations (network requests, file I/O, timers) it would freeze the browser. Asynchronous code allows long-running operations to be initiated and then set aside — JavaScript continues executing other code and comes back to handle the result via a callback, Promise, or async/await when the operation completes. The browser's Web APIs (fetch, setTimeout, DOM events) handle the actual waiting outside the main thread. The event loop then delivers the results back to JavaScript when ready. Example: fetch(url) immediately returns a Promise (asynchronous) — JavaScript does not block waiting for the network. When the response arrives, the .then() callback is queued and executed. All I/O in JavaScript is asynchronous by design to prevent blocking the single thread.