synchronous and asynchronous JavaScript?

  • Synchronous → Code executes line by line (blocking).
  • Asynchronous → Tasks (like API calls, setTimeout) run in the background without blocking code.

Example:

console.log("Start");
setTimeout(() => console.log("Async Task"), 2000);
console.log("End");
// Output: Start → End → (after 2 sec) Async Task

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *