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 script.
2. Microtasks: Promises (C) - These are small tasks that need to be executed ASAP after the current script, 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 script.
2. Microtasks: Promises (C) - These are small tasks that need to be executed ASAP after the current script, 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
73%
Not A Number
3%
No Answer Needed
15%
Notation of Null
9%
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
64%
.push()
18%
.concat()
16%
.pop()
2%
.slice()
What is the Output order for the above code?
Anonymous Quiz
43%
"Hello" β "World"
36%
"World" β "Hello"
13%
Only "Hello"
9%
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
32%
The first element that passes the test
19%
The index of the matching element
42%
A new array with elements that pass the test
6%
The original array without changes
π1
1. CSS isnβt broken β your div just gave up on life.
Try: min-height: 100vh; π
== is for loose relationships.
Use === if you want commitment. π
Want faster sites?
Replace PNGs with webp. Smaller, sharper, sexier. πΈ
2. Centering in CSS used to be sorcery. π§ββοΈ
Now itβs just:
3. Bored of boring bullets?
Spice up your list with:
4.
not working?
Make sure the element isnβt a ghost.
Try: min-height: 100vh; π
== is for loose relationships.
Use === if you want commitment. π
Want faster sites?
Replace PNGs with webp. Smaller, sharper, sexier. πΈ
2. Centering in CSS used to be sorcery. π§ββοΈ
Now itβs just:
display: grid;
place-items: center;
3. Bored of boring bullets?
Spice up your list with:
list-style-type: 'π₯';
4.
z-index
not working?
Make sure the element isnβt a ghost.
position: relative;
β€4