Real world analogy of Sync and Async JavaScript I finally got to understand.
Synchronous Javascript: Imagine you are at Burger King and want to order a delight pack for $5. The waiter starts getting your order ready and then a colleague asked you to order an extra pack meanwhile you already left the queue you have to join in from the back to get another order you don't just walk up front when other customers are waiting for their orders. you wait for your turn. That's Synchronous JavaScript there it waits for a specific request to execute before, moving on to another request.
Asynchronous Javascript: Here it's a different game. Using same analogy. When the customer request for an extra takeout, He doesn't have to wait for other customers orders to be to processed before receiving his. The order is automatically received and he waits for it to be delivered.
So in conclusion, a synchronous code is executed in sequence each request waits for the previous request to finish before executing. Asynchronous code doesn’t have to wait, your request can continue to run in the background while another active request is going on.
I'll also like to get a more in-depth explanation of these concepts as I'm here to learn from everyone.
Top comments (3)
First noticed the word async today. Has been bothering me all day. Thanks for this.
short hand and straight to the point, been reading about it but now with this post i really understand
Very simple, short and yet very insightful. Nice one 👏