Synchronization
Synchronization means tasks are executed one after another in sequence, where each task must finish before the next one starts.
Console.log("Task 1");
Console.log("Task 2");
Console.log("Task 3");
Output
Task 1
Task 2
Task 3
Asynchronization
Asynchronization do not wait for others to complete. some operations like timers, API calls,file reading run in the background and javascript moves on the next task. All functions are not asynchronization.
Console.log("Task 1");
SetTimeout(()=>{
Console.log("Task 2(after 2 seconds)");
},2000;
Console.log("Task 3");
Output
Task 1
Task 3
Task 2 (after 2 seconds)
Top comments (0)