{"id":21542814,"url":"https://github.com/vinitshahdeo/event-loop-in-javascript","last_synced_at":"2025-04-10T04:34:40.366Z","repository":{"id":83691036,"uuid":"256833750","full_name":"vinitshahdeo/Event-Loop-In-JavaScript","owner":"vinitshahdeo","description":"A Webinar on Event loop in JavaScript and rise of Async Programming, organized by HackOn and powered by Coding Blocks","archived":false,"fork":false,"pushed_at":"2020-04-20T11:08:49.000Z","size":12224,"stargazers_count":8,"open_issues_count":1,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T05:51:42.652Z","etag":null,"topics":["asynchronous-programming","coding-blocks","event-loop","hackathon","hackon","javascript","v8-javascript-engine","webapi","youtube-live"],"latest_commit_sha":null,"homepage":"https://bit.ly/hackon-js","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vinitshahdeo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-18T19:16:01.000Z","updated_at":"2021-05-21T21:19:20.000Z","dependencies_parsed_at":"2023-07-04T06:50:32.125Z","dependency_job_id":null,"html_url":"https://github.com/vinitshahdeo/Event-Loop-In-JavaScript","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinitshahdeo%2FEvent-Loop-In-JavaScript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinitshahdeo%2FEvent-Loop-In-JavaScript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinitshahdeo%2FEvent-Loop-In-JavaScript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinitshahdeo%2FEvent-Loop-In-JavaScript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vinitshahdeo","download_url":"https://codeload.github.com/vinitshahdeo/Event-Loop-In-JavaScript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248158081,"owners_count":21057115,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous-programming","coding-blocks","event-loop","hackathon","hackon","javascript","v8-javascript-engine","webapi","youtube-live"],"created_at":"2024-11-24T05:11:25.772Z","updated_at":"2025-04-10T04:34:40.337Z","avatar_url":"https://github.com/vinitshahdeo.png","language":null,"readme":"# Event loop :arrows_counterclockwise: in JavaScript and rise of Asynchronous Behaviour.\n\n[![Poster - HackOn](./assets/poster.jpeg)](https://www.youtube.com/watch?v=zsRv8g3C4rY)\n\n## :red_circle: A webinar by [HackOn Hackathon](https://twitter.com/Vinit_Shahdeo/status/1251819929247993856) :rocket:\n\n# [![YouTube Live](https://img.shields.io/badge/YouTube-Live-tomato.svg?style=for-the-badge\u0026logo=youtube)](http://bit.ly/hackon-js) \n\n\u003e ### Join at [bit.ly/hackon-js](http://bit.ly/hackon-js)\n\n## :confused: Shall I watch?\n\n\u003e **That's a good question!** :raised_hand:\n\nDo a **self analysis of your JS knowledge**, take a pause and predict the output for the below code snippet. :hushed:\n\nIf you're able to predict the correct sequence of log statements, I hope you need not watch the video, **skip to the [takeaways](#five-five-takeaways-bulb) section**. :v: **If not, do watch the [video](https://youtu.be/zsRv8g3C4rY?t=221) and thank me later! :hugs:**\n\n\u003cbr\u003e\n\n```javascript\nconsole.log('Hi!');\n\nconsole.log('Hope you\\'re staying safe at home!');\n\nsetTimeout(() =\u003e console.log('Turn your self isolation into self improvement!'), 1000);\n\nsetTimeout(() =\u003e console.log('Chant, Go Corona, Corona Go 😃'), 0);\t\n\nconsole.log('Thank You!');\n```\n\u003cbr\u003e\n\n## :five: Five Takeaways :bulb:\n\n\u003e GitHub has **maximum number of pull requests in JavaScript repositories**. Check the live stats [here](https://madnight.github.io/githut/#/pull_requests/2020/1). \n\n- JavaScript is **single threaded**, it simply means it has a **single call stack**.\n\n- 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**.\n\n- **`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. \n\n\u003cbr\u003e\n\n\u003e Take a look at the below code:\n\n```javascript\n\nfunction goCorona() {\n   console.log('Stay Home, Stay Safe');\n}\n\nsetTimeout(goCorona, 5000);\n\n```\n\n\u003e 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`.\n\n\u003cbr\u003e\n\n- **`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.\n\n- **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.\n\n\u003cbr\u003e\n\n## About Me\n\n\n```js\n\n// About me\n\nimport { Speaker } from 'HackOn';\n\nlet user =  {\n      Name: 'Vinit Shahdeo',\n      Company: 'Postman',\n      Profile: 'Software Engineer',  // Ex VITian\n      Twitter: '@Vinit_Shahdeo'\n    },\n    title: 'Event loop in JavaScript and rise of Asynchronous behaviour';\n\n_.assign(new Speaker(), user, new Event(title));\n\n```\n\n\u003cbr\u003e\n\n|                                                                                         \u003ca href=\"https://fayz.in/stories/s/1522/0/?ckt_id=ZGL1ZGVk\u0026title=story_of_vinit_shahdeo\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/vinitshahdeo/Water-Monitoring-System/master/assets/vinit-shahdeo.jpg\" width=150px height=150px /\u003e\u003c/a\u003e                                                                                         |\n| :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |\n|                                                                                                                                        **[Vinit Shahdeo](https://www.linkedin.com/in/vinitshahdeo/)**                                                                                                                                        |\n| \u003ca href=\"https://twitter.com/Vinit_Shahdeo\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/vinitshahdeo/Water-Monitoring-System/master/assets/twitter.png\" width=\"32px\" height=\"32px\"\u003e\u003c/a\u003e \u003ca href=\"https://www.facebook.com/vinit.shahdeo\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/vinitshahdeo/Water-Monitoring-System/master/assets/facebook.png\" width=\"32px\" height=\"32px\"\u003e\u003c/a\u003e \u003ca href=\"https://www.linkedin.com/in/vinitshahdeo/\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/vinitshahdeo/Water-Monitoring-System/master/assets/linkedin.png\" width=\"32px\" height=\"32px\"\u003e\u003c/a\u003e |\n\n[![GitHub followers](https://img.shields.io/github/followers/vinitshahdeo.svg?label=Follow%20@vinitshahdeo\u0026style=social)](https://github.com/vinitshahdeo/) \n\n[![Twitter Follow](https://img.shields.io/twitter/follow/Vinit_Shahdeo?style=social)](https://twitter.com/Vinit_Shahdeo)\n\n\u003e **Learn more about me [here](https://fayz.in/stories/s/1522/0/?ckt_id=ZGL1ZGVk).**\n\n#### Well, in this unprecedented time, you all have showed interest. I thank all of you for joining me. :hugs: Stay Safe at home.\n\n:mask: :house:\n\u003cbr\u003e\u003cbr\u003e\n\n```javascript\n/**\n * \n * Let's fight for Corona together!\n */\nfunction stayAtHome() {\n  eat();\n  sleep();\n  code();\n  repeat();\n}\n\nwhile(_.isAlive(new Virus('COVID-19'))) {\n  // Stay home, Stay safe\n  stayAtHome();\n}\n```\n\u003cbr\u003e\n\n## :confused: Any doubts? \n\n\u003e :point_right: You can find the [PPT](https://github.com/vinitshahdeo/Event-Loop-In-JavaScript/blob/master/doc/%5BHack0N%5D%20Event%20loop%20in%20JS%20-%20PDF%20(5).pdf) inside `docs` folder.\n\n### :link: [Click here](https://github.com/vinitshahdeo/Event-Loop-In-JavaScript/raw/master/doc/%5BHack0N%5D%20Event%20loop%20in%20JS%20-%20PDF%20(5).pdf) to download the PPT.\n\n### :fountain_pen: Feel free to shoot your doubts [here](https://github.com/vinitshahdeo/Event-Loop-In-JavaScript/issues/1).\n\n```javascript\n\n  ___      _     ___  ___                  \n / _ \\    | |    |  \\/  |                  \n/ /_\\ \\___| | __ | .  . | ___              \n|  _  / __| |/ / | |\\/| |/ _ \\             \n| | | \\__ \\   \u003c  | |  | |  __/             \n\\_| |_/___/_|\\_\\ \\_|  |_/\\___|             \n                                           \n                                           \n  ___              _   _     _             \n / _ \\            | | | |   (_)            \n/ /_\\ \\_ __  _   _| |_| |__  _ _ __   __ _ \n|  _  | '_ \\| | | | __| '_ \\| | '_ \\ / _` |\n| | | | | | | |_| | |_| | | | | | | | (_| |\n\\_| |_/_| |_|\\__, |\\__|_| |_|_|_| |_|\\__, |\n              __/ |                   __/ |\n             |___/                   |___/ \n\n```\n\n\u003cbr\u003e\n\n## :bowtie: Checkout my recent works below:\n\n\u003e [![GitHub stars - COVID-19 Vinit Shahdeo](https://img.shields.io/github/stars/vinitshahdeo/COVID19?label=LEAVE%20A%20Star%20on%20GitHub\u0026logo=github\u0026style=for-the-badge)](https://github.com/vinitshahdeo/COVID19/)\n\n- ### [Live Updates of Reported Corona Cases](http://corona-cases-india.netlify.com/) :mask:\n- ### [COVID-19 Tracker :bar_chart: | INDIA :india:](https://indiafightscorona.netlify.app/)\n- ### Consider leaving a star :star: [here](https://github.com/vinitshahdeo/COVID19).\u003csup\u003eTo be open-sourced pretty soon.\u003c/strong\u003e\u003c/sup\u003e\n\n\u003cbr\u003e\n\n---\n\n```javascript\n// thank you :)\n\nconst THANK_YOU_MSG = `Thank you so much for being here! \n\tyou were an amazing audience`;\n\nlet sayThanks = (viewer) =\u003e { return THANK_YOU_MSG };\n\n_.forEach(allViewers, function (viewer) {\n\t_.times(Number.MAX_SAFE_INTEGER, sayThanks(viewer));\n});\n\n```\n---\n\n[![Thank you for watching this](./assets/thank-you.gif)](https://youtu.be/zsRv8g3C4rY?t=215)\n\n[![Twitter Follow](https://img.shields.io/twitter/follow/Vinit_Shahdeo?style=social)](https://twitter.com/Vinit_Shahdeo)\n [![GitHub followers](https://img.shields.io/github/followers/vinitshahdeo.svg?label=Follow%20@vinitshahdeo\u0026style=social)](https://github.com/vinitshahdeo/) \n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinitshahdeo%2Fevent-loop-in-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvinitshahdeo%2Fevent-loop-in-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinitshahdeo%2Fevent-loop-in-javascript/lists"}