Careeroza
Asynchronous Code
Do Not Wait
Asynchronous code starts a task (timer, network request, file read) and continues immediately. The result is handled later by a callback, promise or await.
Example
Notice that "End" prints before the timeout, even with a 0 ms delay.
console.log('Start');
setTimeout(() => console.log('Timeout finished'), 0);
console.log('End');Output
Start End Timeout finished
Sync vs Async
| Synchronous | Asynchronous | |
|---|---|---|
| Execution | in order, one after another | starts now, finishes later |
| Blocks the thread | yes | no |
| Examples | loops, math, array methods | fetch, setTimeout, file/DB access |
| Handled with | normal code | callbacks, promises, async/await |