#events #eventloop #javascript
This video covers the concept of event loop in Javascript. After watching this video, you will have a greater understanding of how Javascript is capable of handling asynchronous events even though the runtime is single threaded.
This video covers callback functions. To learn more about promises, check out our video dedicated to promises here:
Original source
48 responses to “Javascript event loop | Every Javascript developer must know !”
Thansk for your sharing and explanation 🙂
This is one superb video and amazing explanation …so simplified that anyone can understand easily.Keep up the good work!!
Aloha , Gama, beta
Alpha
Gamma
Beta
This the order
Nice video explanation keep post more vedios
Alpha, gama, beta
Alpa, gamma, and beta
alpha gamma beta
Isn’t JavaScript single threaded SYNCHRONOUS , your are saying it’s ASYNCHRONOUS and single threaded
What is meant by Function Stack becomes empty at 6:47 .?
Even if you do:
function fun(){
console.log("alpha");
setTimeout(console.log("beta"), 5000);
console.log('gama');
}
it is: alpha beta gama.
Callback matters here.
Answer will be alpha , gamma , beta . Explanation : Even there is no delay in setTimeout i.e 0 seconds but since setTimeout will be delegated to browser's web api , which will store the execution of function inside setTimeout in Event Queue. Now the function inside this event queue will be only executed once the entire call stack is empty . Now already func is in call stack and it will be only removed from the call stack when entire function is executed that console.log(''gamma") is printed . Now after this only call stack will be empty and function stored in event queue (i.e console.log('beta")) will get a chance to execute. Hence the answer is alpha , gamma , beta.
Thank you so much, result will be alpha, gama, beta
javascript is synchronos, not asynchronos! its a common mistake. the browsers added functionality for javascript to be asynchronos!
Man love you 3000 ❤
I'm looking for an well explained answer for How Javascript actually works? and no one explained that better than you.
Alpha,
Gamma
Beta
Thanks…. superb explanation
Best lesson on event loop
Alpha , Gama , beta
Alpha gamma beta
Alpha gamma beta
alpha
gamma
beta
Good explanation of the event loop.Please make a video on microtask queue as well and compare with the event queue.
javascript by default Synchronous not aSynchronous which you are saying in beginning.
the music is awful and loud. the instructor is already difficult to understand but the music makes listening even worse! Get rid of it please!
I have a doubt, is the event loop part of core JavaScript or nodejs?
Thank you very much!
The setTimeout should accept a callback ' setTimeout(()=>{console.log('beta')}, 0)
'
Hey, a couple of pointers – the volume is too low, background music is too loud/unnecessary. Thanks for the lesson though.
This is a brilliant video. Thanks!
is that music behind ur voice necessary? quite disturbing.
This explanation is great. One question though, for Node.js, what is used instead of the "Web APIs"?
Thank You
good one
Alpha
Gamma
Beta
Awesome video. Thanks for the explanation 🙂
my console shows
alpha
beta
gamma
function func() {
console.log("alpha");
setTimeout(console.log("beta"), 0);
console.log("gama");
}
func();
what did i do wrong =/
amazing. and I love the background music. its meditating.
atleast i suggest to refer the link of the source where you get learn all this, phillip roberts who initially explained this
https://www.youtube.com/watch?v=8aGhZQkoFbQ
Ewwwwww.. that loud BG music.. :@
first of all print alpha, beta then It will give the error because callback function is not written in the setTimeout function. it needs the callback function to run as asynchronous.
How are promises handled in this case? They are asynchronous?
Great video
good video but BGM is annoying
background music is really irritatimg.. else nice logic explained.
function func(){
console.log("alpha");
setTimeout(function(){
console.log("beta");
},0);
console.log("gamma");
}
func();
Answer
alpha
gamma
beta
alpha
gama
beta
1. Alpha 2. Gamma 3. Beta
Because setTimeout is not executed synchronously but via Event Queue by Event Loop.