Synchronous vs. Asynchronous
1. Synchronous
JavaScript executes synchronous code one statement at a time, in order. Each operation must finish before the next one starts.
Output: 1, 2, 3
Simple, predictable, and sequential.
2. Asynchronous
Asynchronous operations allow JavaScript to continue executing other code without waiting for them to finish.
Output: Leave in the comments 👇
js
console.log("1"); console.log("2"); console.log("3");
js
console.log("1"); setTimeout(() => { console.log("2"); }, 1000); console.log("3");
commit e9eb14b