Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoseph Bertino
Full Stack JavaScript Techdegree Student 14,652 PointsEvent Loop
So the Event Loop ONLY pushes callback functions to the call stack when the call stack is Completely empty? That seems wrong and/or inefficient, and yet that's what the wording implies in this instruction
2 Answers
Brandon White
Full Stack JavaScript Techdegree Graduate 34,662 PointsHi Joseph,
That’s essentially correct. The event loop can only move a function from the queue to the stack when the stack is empty.
And since callback functions are asynchronous, they’re moved from the browser to the queue. And that’s where they wait until the stack is ready.
Anoop S
Python Development Techdegree Student 30 PointsAll callback functions are pushed into the callback queue even if call stack is empty. The event loop pops the callback functions one by one from the callback queue and transfers them to call stack for execution. Read how the event loop and callback queue work: https://www.datainfinities.com/10/event-loop-and-callback-queue-in-javascript
Joseph Bertino
Full Stack JavaScript Techdegree Student 14,652 PointsJoseph Bertino
Full Stack JavaScript Techdegree Student 14,652 PointsThanks Brandon... This stackoverflow thread also helped me out a lot: [https://stackoverflow.com/questions/52906975/call-stack-event-loop-why-waiting-for-empty-stack]