JavaScript Event Loop: The Truth About setTimeout(0)
The Real Order of Operations:
1. Call Stack: Synchronous code (A, D) - This is where JavaScript executes code sequentially, like reading a noscript.
2. Microtasks: Promises (C) - These are small tasks that need to be executed ASAP after the current noscript, before the next rendering. Think of them as urgent side tasks.
3. Macrotasks: Timeouts/Intervals (B) - These are longer tasks that the browser queues up to do whenever it gets a chance. They're not as urgent as microtasks.
Golden Rule: "0ms" doesn't mean immediate - it means "next event loop tick".
The Real Order of Operations:
1. Call Stack: Synchronous code (A, D) - This is where JavaScript executes code sequentially, like reading a noscript.
2. Microtasks: Promises (C) - These are small tasks that need to be executed ASAP after the current noscript, before the next rendering. Think of them as urgent side tasks.
3. Macrotasks: Timeouts/Intervals (B) - These are longer tasks that the browser queues up to do whenever it gets a chance. They're not as urgent as microtasks.
Golden Rule: "0ms" doesn't mean immediate - it means "next event loop tick".
❤6
🧩 JavaScript Quiz
In JavaScript, what does the "NaN" stand for?
In JavaScript, what does the "NaN" stand for?
Anonymous Quiz
74%
Not A Number
4%
No Answer Needed
14%
Notation of Null
8%
Negative Absolute Number
👍3
🧩 JavaScript Quiz
Which method is used to add an element to the end of an array?
Which method is used to add an element to the end of an array?
Anonymous Quiz
72%
.push()
15%
.concat()
12%
.pop()
2%
.slice()
What is the Output order for the above code?
Anonymous Quiz
45%
"Hello" → "World"
31%
"World" → "Hello"
13%
Only "Hello"
11%
Race condition
preventDefault() vs stopPropagation() vs stopImmediatePropagation()
When to Use What:
📌preventDefault(): When you want to handle the action yourself
📌 stopPropagation(): When parent elements shouldn't react
📌 stopImmediatePropagation(): Nuclear option for plugin conflicts
90% of the time, you only need preventDefault().
When to Use What:
📌preventDefault(): When you want to handle the action yourself
📌 stopPropagation(): When parent elements shouldn't react
📌 stopImmediatePropagation(): Nuclear option for plugin conflicts
90% of the time, you only need preventDefault().
❤2👍1
🧠 JavaScript Quiz
What does Array.prototype.filter() return?
What does Array.prototype.filter() return?
Anonymous Quiz
28%
The first element that passes the test
23%
The index of the matching element
41%
A new array with elements that pass the test
8%
The original array without changes
👍1