Pratham Profile picture
5 Jun, 13 tweets, 3 min read
Introduction to Event Loop ➰

Event loop is the confusing concept in JavaScript but you need to know about it because whole JavaScript is based on this programming construct.

Let's try to understand it in a simple way 🧵👇🏻
Before diving into it, we need to understand what multithreading is?

Multithreading is nothing but a programming feature by which we can make maximum use of CPU by running two or more parts of program simultaneously
📌 What exactly event loop is?

Event loop is a programming concept or design pattern that makes the JavaScript a multithreaded language
📌 Lets break the Event loop and see what we find inside

Event loop is made up of two data structures

1. Stack
2. Queue
Call stack

It keeps all the operations in order which has to be executed. After successful execution of a operation, it is popped out.
Event Queue

It is responsible for sending new functions to the call stack for processing. It follows the queue data structure to maintain the correct sequence in which all operations should be sent for execution.
So far everything is normal. Lets try to visualize it. Consider the following code and output 👇🏻 console.log("one"); console.log("two");
As you can see, one, two and three is being printed out as they appeared in the code in serial order.

But now consider this piece of code 👇🏻 console.log("one"); setTimeout(() => {   console.l
The output in this particular case is

one
three
two

Why did this happen?
📌 Web API

This is where the browser API or web API comes into play. These API are pre built into the browsers.

Whenver an async function comes is call stack, it is sent to web API which waits for the specified time to send this operation back to event queue
So, setTimeout function was sent to web API, which waited there for specific time period and after that it was sent to queue for processing

That's why the output of above code is

one
three
two
Hence these three components, The call stack, the event queue and the web APIs makes a cycle which is known as event loop.
As simple as that, If you like this thread, share it with your connections.

Peace out 😉

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Pratham

Pratham Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Prathkum

7 Jun
Web development is all about exploration. If you are learning this, explore more and learn more from these websites

🧵 👇🏻
📌 HTML

1. Learn HTML
learn-html.org

2. HTML best practice
hail2u.github.io/html-best-prac…

3. HTML reference
htmlreference.io Image
📌 CSS

1. CSS reference
cssreference.io

2. Learn to code
learn.shayhowe.com

3. CSS layout
learnlayout.com

4. CSS tutorial
csstutorial.net

5. Learn about colors
hexinvaders.com Image
Read 4 tweets
7 Jun
5 HTML features probably you haven't heard yet

🧵👇🏻
1️⃣ enterkeyhint attribute

The enterkeyhint is a global attribute defines the action for "enter" key on virtual keyboard

It accpets the following values 👇🏻 Image
2️⃣ sizes attribute

You may have heard about "size" attribute but did you know about "sizes" attribute?

The sizes attribute specifies the sizes of icons for visual media.

Check the compatibility here caniuse.com/?search=sizes Image
Read 7 tweets
5 Jun
Check out these 3 things that will prove how powerful CSS is

🧵👇🏻
1️⃣ Pure CSS Typewriter effect

- You can create cool typing effect using steps() function of animation-timing-function
Check out the full source code here 👇🏻

codepen.io/prathamkumar/p…
Read 7 tweets
5 Jun
CSS is also a deep module of web development. There are over 250 unique properties

Do we need to learn them all? Let's try to figure out how much CSS will be enough

🧵 👇🏻
CSS is an amazing and unique language that servers a great purpose. We can make our website visually good using CSS. It describe the presentation of web pages, including typography,. layouts, color etc...
CSS is totally operates on properties value pair. And there are around ~300 distinct properties in CSS
Read 17 tweets
3 Jun
5 great websites a web developer should visit

Thread 🧵 👇🏻
1. Can I use?

- A website that provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.

🔗 caniuse.com
2. Web Skills

Websites for all kind of learning resources for web developers

- Fundamentals
- Accessibility
- Web components
- Progressive web apps
- Frameworks and libraries
- Testing
- Architecture and Paradigm
- UI and UX
- DS and Algo

🔗 andreasbm.github.io/web-skills/
Read 6 tweets
3 Jun
Are you new in the field of Web development or planning to start with it?
This is how you can start with total ease.

🧵 👇🏻
Getting started with web development is little tricky and tedious. I personally faced some difficulties when I was first learning it.

But you don't have to worry. In this thread we will make the process easier
Three different languages you need to learn

HTML
CSS
JavaScript

You need to learn these 3 things in a chronological order
Read 26 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(