๐ค Now the logical next question is: How does Javascript behave like async when it actually is synchronous and has a single stack?
๐ Read along to find out!
๐ Read along to find out!
๐ฏ So how exactly does Javascript manage to do something that can not be done by a single threaded language despite being one?
โ The answer is - it doesn't.
๐ Javscript is synchronous and it can't do async tasks!
โ The answer is - it doesn't.
๐ Javscript is synchronous and it can't do async tasks!
๐คญ Javascript doesn't do any asynchronous task.
๐ญ Remember the paperboy analogy from my previous thread ( linked above ).
๐ฒ The paperboy throws in the newspaper, moves to the next house while his helper waits for the payment.
๐ญ Remember the paperboy analogy from my previous thread ( linked above ).
๐ฒ The paperboy throws in the newspaper, moves to the next house while his helper waits for the payment.
๐ก And just like it is the job of the helper to collect the payment on behalf of paperboy, in the browser it is the job of web APIs to run the async task and report back the results while Javascript keeps on executing more code.
๐ So, essentially Javascript manages to do asynchronous tasks despite being a synchronous language because it is assisted by a magical helper called Web API.
โก And it is browsers that provide Javascript with the web API.
โ Vanilla Javascript doesn't have it on its own!
โก And it is browsers that provide Javascript with the web API.
โ Vanilla Javascript doesn't have it on its own!
๐ก And that's how Javascript manage to handle asynchronous tasks despite being a synchronous language.
โ I'll be doing another thread on how web APIs work and explain call stack, event loop, job queue in detail, so make sure you have tweet notifications turned on.
โ I'll be doing another thread on how web APIs work and explain call stack, event loop, job queue in detail, so make sure you have tweet notifications turned on.
I write daily threads on web dev, so if you enjoyed this thread, please:
โ Follow me @sumitsaurabh927 for more of these.
โ RT the tweet below to show me some ๐งก and comment your thoughts.
๐ Your each like, every comment motivates me to come up with awesome new stuff!
โ Follow me @sumitsaurabh927 for more of these.
โ RT the tweet below to show me some ๐งก and comment your thoughts.
๐ Your each like, every comment motivates me to come up with awesome new stuff!
Loading suggestions...