Skip to content

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

License

Notifications You must be signed in to change notification settings

vinitshahdeo/Event-Loop-In-JavaScript

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:

function goCorona() {
   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 me

import { Speaker } from 'HackOn';

let user =  {
      Name: 'Vinit Shahdeo',
      Company: 'Postman',
      Profile: 'Software Engineer',  // Ex VITian
      Twitter: '@Vinit_Shahdeo'
    },
    title: 'Event loop in JavaScript and rise of Asynchronous behaviour';

_.assign(new Speaker(), user, new Event(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!
 */
function stayAtHome() {
  eat();
  sleep();
  code();
  repeat();
}

while(_.isAlive(new Virus('COVID-19'))) {
  // Stay home, Stay safe
  stayAtHome();
}

๐Ÿ˜• 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 :)

const THANK_YOU_MSG = `Thank you so much for being here! 
	you were an amazing audience`;

let sayThanks = (viewer) => { return THANK_YOU_MSG };

_.forEach(allViewers, function (viewer) {
	_.times(Number.MAX_SAFE_INTEGER, sayThanks(viewer));
});

Thank you for watching this

Twitter Follow GitHub followers

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published