Skip to content

Commit ac5fd77

Browse files
committed
event loop
1 parent b24251e commit ac5fd77

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

E/event-loop/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,37 @@ Macrotask
2929
settimeout , click etc
3030

3131
Mutation Observer
32+
33+
34+
## Priorty
35+
36+
# JavaScript Execution Priority Order
37+
38+
## 1️⃣ Call Stack (Synchronous Code) - **Highest Priority**
39+
- Executes **immediately** in order.
40+
- Examples:
41+
- `console.log("Hi")`
42+
- Variable declarations
43+
- Function executions
44+
45+
## 2️⃣ Micro-task Queue (Higher Priority than Macro-task)
46+
- **Promises (`.then()`, `.catch()`, `.finally()`)**
47+
- **Async/Await (`await` resumes here)**
48+
- **MutationObserver (rarely used)**
49+
- These tasks execute **immediately after synchronous code finishes**.
50+
- Examples:
51+
```js
52+
Promise.resolve().then(() => console.log("Microtask"));
53+
54+
## 3️⃣ Macro-tasks (setTimeout, setInterval, setImmediate, I/O)
55+
- setTimeout, setInterval, setImmediate (Node.js)
56+
- I/O tasks (like reading files in Node.js)
57+
- UI rendering tasks (in browsers)
58+
- Runs after all micro-tasks are completed.
59+
60+
## 4️⃣ Render tasks (UI updates, reflows, repaints)
61+
UI updates, painting, and rendering.
62+
Executed after Micro-tasks and Macro-tasks.
63+
Examples:
64+
DOM updates after JavaScript execution
65+
CSS animations, reflows, repaints

P/promises/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ p.then((data)=>{
2020
console.log(err.message);
2121
});
2222
```
23+
Yes, you can write .then() after .finally() in a Promise chain. However, it's important to understand how .finally() works:
24+
## Finally ()
25+
Key Rules:
26+
.finally() does not modify the resolved value—it just executes and passes the previous value unchanged.
27+
If .finally() returns a value, it is ignored.
28+
If .finally() throws an error, the next .then() will not run, but the next .catch() will handle the error.
29+
2330

2431
## How Promises and Timers Work
2532
### Promise Creation:

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Below is an overview of the JavaScript topics included in each folder:
4747

4848
## TODO
4949
- indexedDB
50+
- priorty of Execution in eventloop
5051

5152
## How to Use
5253

links.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Important Links
2+
3+
- [Practice Javascript Logic](http://teachertrek.in/#/js-logic-building)

0 commit comments

Comments
 (0)