Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

50 Commits

Repository files navigation

Event loop 🔄 in JavaScript and rise of Asynchronous Behaviour.

Poster - HackOn

🔴 A webinar by HackOn Hackathon 🚀

YouTube Live

😕 Shall I watch?

That's a good question!

Do a self analysis of your JS knowledge, take a pause and predict the output for the below code snippet. 😯

If you're able to predict the correct sequence of log statements, I hope you need not watch the video, skip to the takeaways section. ✌️ If not, do watch the video and thank me later! 🤗


console.log('Hi!');console.log('Hope you\'re staying safe at home!');setTimeout(()=>console.log('Turn your self isolation into self improvement!'),1000);setTimeout(()=>console.log('Chant, Go Corona, Corona Go 😃'),0);console.log('Thank You!');

5️⃣ Five Takeaways 💡

GitHub has maximum number of pull requests in JavaScript repositories. Check the live stats here.

  • JavaScript is single threaded, it simply means it has a single call stack.

  • The asynchronous behaviour is not part of the JavaScript language itself, rather they are built on top of the core JavaScript language in the browser (or the programming environment) and accessed through the browser APIs.

  • setTimeout(function, delay) does not stand for the precise time delay after which the function is executed. It stands for the minimum wait time after which at some point in time the function will be executed.


Take a look at the below code:

functiongoCorona(){console.log('Stay Home, Stay Safe');}setTimeout(goCorona,5000);

That doesn’t mean that goCorona will be executed in 5s but rather that, in 5000 ms, goCorona will be added to the queue. The queue, however, might have other events that have been added earlier — the function goCorona will have to wait. The idea here is the above code gaurantees that Stay Home, Stay Safe will be printed anytime after 5000ms.


  • setTimeout returns timeoutID - The returned timeoutID is a positive integer value which identifies the timer created by the call to setTimeout(). This value can be passed to clearTimeout() to cancel the timeout.

  • The Event Loop has one simple job — to watch the Call Stack and the Callback Queue. If the Call Stack is empty, it will take the first event from the queue and will push it to the Call Stack, which effectively runs it.


About Me

// About meimport{Speaker}from'HackOn';
let user={Name: 'Vinit Shahdeo',Company: 'Postman',Profile: 'Software Engineer',// Ex VITianTwitter: '@Vinit_Shahdeo'},title: 'Event loop in JavaScript and rise of Asynchronous behaviour';_.assign(newSpeaker(),user,newEvent(title));

Vinit Shahdeo

GitHub followers

Twitter Follow

Learn more about me here.

Well, in this unprecedented time, you all have showed interest. I thank all of you for joining me. 🤗 Stay Safe at home.

😷 🏠

/** *  * Let's fight for Corona together! */functionstayAtHome(){eat();sleep();code();repeat();}while(_.isAlive(newVirus('COVID-19'))){// Stay home, Stay safestayAtHome();}

😕 Any doubts?

👉 You can find the PPT inside docs folder.

🔗 Click here to download the PPT.

🖋️ Feel free to shoot your doubts here.

__________/_ \ ||| \/|//_\ \___||__|..|___|_/__||//||\/||/_\ ||| \__ \ <||||__/ \_||_/___/_|\_\ \_||_/\___|______/_ \ ||||(_)//_\ \_____||_||_________|_|'_ \| | | | __| '_ \|| '_ \ / _` |
||||||||_|||_||||||||(_||
\_||_/_||_|\__,|\__|_||_|_|_||_|\__,|__/|__/||___/|___/

:bowtie: Checkout my recent works below:

GitHub stars - COVID-19 Vinit Shahdeo



// thank you :)constTHANK_YOU_MSG=`Thank you so much for being here! 	you were an amazing audience`;letsayThanks=(viewer)=>{returnTHANK_YOU_MSG};_.forEach(allViewers,function(viewer){_.times(Number.MAX_SAFE_INTEGER,sayThanks(viewer));});

Thank you for watching this

Twitter FollowGitHub followers

About

A Webinar on Event loop in JavaScript and rise of Async Programming, organized by HackOn and powered by Coding Blocks

Topics

Resources

Stars

8 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors