Event loop


So as far as I understood from the MDN document regarding the event loop is that it is meant to delay some tasks in order to carry out other tasks first and just guide javascript regarding a sequence it should follow when executing javascript code…so can’t we just put the code in the arrangement we want it to be executed in considering they will be arranged as such in stack anyways so we can just add what we want executed later lower in the document, no? I am a little confused about this topic right now


that won’t work. If you truly wish to understand this in more depth i can highly recommend this book:


actually, all the books in this series (you don’t know javascript by kyle simpson) are highly recommended.

We first need to make a distinction, just like all pieces of software, programming language get updates. es6 (also known as emcascript 2015, is the latest version of JS), before the release of es6 the web used es5

javascript is an asynchronous non-linear language, which is confusing. Lets say i ask you a question, i then wait for you to reply before asking my next question. this is synchronous, while javascript might fire multiple questions in a single go and the response might not come back in order. Javascript isn’t waiting.

javascript might also ask questions now, and then have more questions later.

these “questions” of javascript might be requests to server, for example loading new replies on this topic

its such a difficult concept to explain, because its so different from how our brains work (as beautiful described by kyle simpson)


I see, I read some more articles on this while you replied and coupled with your reply I think I have made a little progress in my concepts but thank you for the book recommendation! books always help, I’ll be sure to buy it asap


The whole version of the book is on github, but yea, it would be good to buy as well. Its well written.

but putting code you want to execute later in the document won’t work, for example if you take a look at the the list of latest topics on this forum:


you see a list of topics, but this is just a small fraction of all existing topics. When you scroll down, new topics will be loaded (you see this with facebook as well for example), so you want to load more topics later, but when? That depends on the user. Or the user might not scroll at all, so you don’t want to load more topics at all.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.