_thorbah Profile Banner
tóbà Profile
tóbà

@_thorbah

Followers
3
Following
5
Media
24
Statuses
164

Turning coffee into code ☕ | Learning JavaScript, Python, & Solidity | Sharing my dev journey one bug at a time 🐛💻

Joined February 2024
Don't wanna be here? Send us removal request.
@_thorbah
tóbà
1 year
Starting my coding journey today! 💻 Prepare for a wild ride of breakthroughs, facepalms, and everything in between. Watch as I turn curiosity into code, one bug at a time! 🐛🚀 #100DaysOfCode #DevJourney
0
0
2
@rahul_meX
Rahul Gujjar
27 days
I barely do DSA, but every time I watch @_DhruvPasricha explain a tough problem I feel like, "Okay maybe I can do this too" :-) lol He's seriously too good at teaching!
7
23
436
@_thorbah
tóbà
1 year
Writing code is 10% typing and 90% googling errors you never thought were possible. 😅 Who else feels like Stack Overflow deserves a ‘thank you’ in their project credits? Let’s connect and swap coding tips! 🤝 #DevLife #Programming
0
0
0
@_thorbah
tóbà
1 year
Programming is like solving a puzzle 🧩— every bug is just a missing piece. What’s the most satisfying bug you’ve squashed recently? Share your wins! 🚀 Looking to #connect with fellow coders, let’s grow together! 🤝 #CodeWins #Programming #DevCommunity
1
0
1
@_thorbah
tóbà
1 year
The Power of Small: A Journey Beyond Giants https://t.co/efzZB6ejsy via @YouTube
0
0
0
@_thorbah
tóbà
1 year
That's a wrap on our Event Loop deep dive! Remember, in the grand theater of JavaScript, the Event Loop is the unsung hero working tirelessly behind the scenes to make the magic happen. Take a bow, Event Loop! 🎭👏 #JavaScript #EventLoop #100DaysOfCode
0
0
1
@_thorbah
tóbà
1 year
Understanding the Event Loop is crucial for writing efficient JavaScript code. It helps you predict how your asynchronous code will behave and avoid common pitfalls like race conditions or blocking operations. 🏁
1
0
0
@_thorbah
tóbà
1 year
In Node.js, the Event Loop has additional phases: 1. Timers: setTimeout, setInterval callbacks 2. Pending callbacks: I/O callbacks 3. Idle, prepare: internal use 4. Poll: retrieve new I/O events 5. Check: setImmediate callbacks 6. Close callbacks: e.g., socket.on('close', ...)
1
0
0
@_thorbah
tóbà
1 year
To help with this, Node.js introduced the setImmediate function. It's similar to `setTimeout(fn, 0)`, but with some subtle differences in how it's queued. 🔜
1
0
0
@_thorbah
tóbà
1 year
But beware! Long-running tasks on the call stack can block the Event Loop, making your app unresponsive. This is why it's crucial to keep your synchronous operations light and fast. ⚡
1
0
0
@_thorbah
tóbà
1 year
This non-blocking I/O is what makes Node.js so efficient for building scalable network applications. It can handle many concurrent connections without the overhead of managing threads. 🚀
1
0
0
@_thorbah
tóbà
1 year
The Event Loop also plays a crucial role in handling I/O operations. When you make an AJAX request, for example, the callback goes into the queue once the response is received. 📡
1
0
0
@_thorbah
tóbà
1 year
Now microtask queue is empty, so we move to callback queue: 10. 'Timeout 1' logs 11. 'Timeout 2' logs
1
0
0
@_thorbah
tóbà
1 year
Event loop sees microtask queue has items: 6. 'Promise 1' logs 7. Timeout 2 goes to callback queue 8. Promise 2 goes to microtask queue 9. Microtask queue still not empty, so 'Promise 2' logs
1
0
0
@_thorbah
tóbà
1 year
Can you guess the output? Let's break it down: 1. 'Start' logs 2. Timeout 1 goes to callback queue 3. Promise 1 goes to microtask queue '4. End' logs 5. Call stack empties, event loop checks queues
1
0
0
@_thorbah
tóbà
1 year
This means microtasks can delay rendering! If a microtask adds more microtasks, they all run before rendering. It's like if VIPs kept inviting friends to cut in line! 👯‍♀️
1
0
0
@_thorbah
tóbà
1 year
Now, let's dive deeper into how the Event Loop processes these queues. After each task in the callback queue: 1. All microtasks are processed 2. UI rendering updates happen 3. Next task from the callback queue is processed
1
0
0
@_thorbah
tóbà
1 year
Microtask Queue: This is like a VIP line at our theme park. It's where callbacks from Promises and mutation observers wait. These get priority over the regular callback queue. 🥇
1
0
0
@_thorbah
tóbà
1 year
The execution flow: 1. 'Start' is logged 2. setTimeout is processed by Web API 3. 'End' is logged 4. Call stack empties 5. Event loop sees an empty call stack, pushes setTimeout callback to it 6. 'Timeout' is logged
1
0
0
@_thorbah
tóbà
1 year
Even though we set the timeout to 0ms, 'Timeout' is printed last. Why? Because setTimeout is a Web API. Its callback goes to the callback queue, and waits for the call stack to be empty. 🕰️
1
0
0
@_thorbah
tóbà
1 year
Callback Queue (also known as Task Queue): This is where callbacks from Web APIs wait their turn to be executed. It's like a line at a theme park ride - first in, first out! 🎢
1
0
0