Understand synchronous Vs asynchronous code in Js

Synchronous code runs step by step where each step has to wait for previous one to be executed.

Example:

console.log(“Hello Friends”);
console.log(“Hello”);
console.log(“Nice to meet you”);

Here each line will execute then next until all fini…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Twizeyimana Elissa

Synchronous code runs step by step where each step has to wait for previous one to be executed.

Example:

console.log("Hello Friends");
console.log("Hello");
console.log("Nice to meet you");

Here each line will execute then next until all finish.

Image description

But for asynchronous code it doesn't respect order stuff ,it get executed out of sequence.
Example:

console.log("Hello");
setTimeout(()=>console.log("Wait for 3 Second"),3000);
console.log("See you again");

First line will execute and last while for second one it has to wait for 3seconds to it will execute last.

Image description
I'm grateful that you took the time to read my writing, and I hope it will help you develop. Let's collaborate to brighten the future. All of my primary profiles are available on My Github


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Twizeyimana Elissa


Print Share Comment Cite Upload Translate Updates
APA

Twizeyimana Elissa | Sciencx (2022-09-21T22:43:14+00:00) Understand synchronous Vs asynchronous code in Js. Retrieved from https://www.scien.cx/2022/09/21/understand-synchronous-vs-asynchronous-code-in-js/

MLA
" » Understand synchronous Vs asynchronous code in Js." Twizeyimana Elissa | Sciencx - Wednesday September 21, 2022, https://www.scien.cx/2022/09/21/understand-synchronous-vs-asynchronous-code-in-js/
HARVARD
Twizeyimana Elissa | Sciencx Wednesday September 21, 2022 » Understand synchronous Vs asynchronous code in Js., viewed ,<https://www.scien.cx/2022/09/21/understand-synchronous-vs-asynchronous-code-in-js/>
VANCOUVER
Twizeyimana Elissa | Sciencx - » Understand synchronous Vs asynchronous code in Js. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/09/21/understand-synchronous-vs-asynchronous-code-in-js/
CHICAGO
" » Understand synchronous Vs asynchronous code in Js." Twizeyimana Elissa | Sciencx - Accessed . https://www.scien.cx/2022/09/21/understand-synchronous-vs-asynchronous-code-in-js/
IEEE
" » Understand synchronous Vs asynchronous code in Js." Twizeyimana Elissa | Sciencx [Online]. Available: https://www.scien.cx/2022/09/21/understand-synchronous-vs-asynchronous-code-in-js/. [Accessed: ]
rf:citation
» Understand synchronous Vs asynchronous code in Js | Twizeyimana Elissa | Sciencx | https://www.scien.cx/2022/09/21/understand-synchronous-vs-asynchronous-code-in-js/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.