DEV Community

Cover image for 🚀 Let’s Learn Event Loops in JavaScript! 🎡

🚀 Let’s Learn Event Loops in JavaScript! 🎡

Jagroop Singh on November 26, 2024

Hey there, JavaScript enthusiast! 👋 Are you ready to unravel the magic behind event loops? It's one of the most exciting (and misunderstood) concep...
Collapse
 
jimzord12 profile image
jimzord12

If I am reading this correctly, currently the function heavyTask() creates a macrotask for every single incrementation. This probably introduces some overhead.

For further optimization, I believe creating batched macrotasks or using web workers might be even better.

I would suggest combining both techniques and create multiple web workers (e.g., 10) and split the work among them.

If you anyone has a way for even better optimization, I would love to hear it.

Collapse
 
john12 profile image
john

it's answer is B

Collapse
 
jagroop2001 profile image
Jagroop Singh

Yes , @john12 , it's correct.

Collapse
 
hng_thc_7942da846939a35 profile image
Hồng Thức

B is the correct answer

Collapse
 
jagroop2001 profile image
Jagroop Singh

Well done!

Collapse
 
nidhi_sharma_3ce9c763fc04 profile image
nidhi sharma

Answer is b

Collapse
 
jagroop2001 profile image
Jagroop Singh

Indeed

Collapse
 
moglimanani profile image
manimaran

B

Collapse
 
jagroop2001 profile image
Jagroop Singh

Yes @moglimanani , it's correct. Do you know the reason ?

Collapse
 
anand_gautam_608efaa21e58 profile image
Anand Gautam

B

Collapse
 
jagroop2001 profile image
Jagroop Singh

Absolutely right @anand_gautam_608efaa21e58 . Do you the know the reason of it's correctness ?

Collapse
 
emybel profile image
Imane BELAID

B is the right answer.

Collapse
 
jagroop2001 profile image
Jagroop Singh

correct @emybel !!

Collapse
 
shivani_singh_399f24510a6 profile image
Shivani Singh

The answer is B

Collapse
 
jagroop2001 profile image
Jagroop Singh

Absolutely right @shivani_singh_399f24510a6

Collapse
 
muhammad_usama_db59ea3065 profile image
Muhammad Usama

B

Collapse
 
jagroop2001 profile image
Jagroop Singh

Spot on !

Collapse
 
fandyvn profile image
Fandy

B. 1️⃣ Hello, 4️⃣ Goodbye, 3️⃣ Promise, 2️⃣ Timeout
Thanks

Collapse
 
jagroop2001 profile image
Jagroop Singh

@fandyvn , yes it's correct.

Collapse
 
_ndeyefatoudiop profile image
Ndeye Fatou Diop

Very cool post 😎

Collapse
 
bobbyleex profile image
BobbyleeX • Edited

B

Collapse
 
oks_oksanium_31c16c47d57d profile image
Oks Oksanium

What does the code after the line "Better Example (Using setTimeout for Chunking)" mean? Is it infinity recursion? Why?