👀 JS Macro vs Micro tasks: A very important concept of JS, often ignored, but can put you in hours long debugging sessions 😂 🧩 Basically, JS doesn’t just have one queue — it has two (if categorized majorly on priority basis): Macrotasks: timers, I/O, setTimeout, etc. Microtasks: promises, queueMicrotask, process.nextTick etc. Microtasks run right after the current stack — before the next macrotask. So even a setTimeout(..., 0) gets delayed behind promises. That’s why code like attached image prints in this order: ``` promise timeout ``` You can read more about this in the article below: https://lnkd.in/gEjWn3_S #JavaScript #NodeJS #EventLoop #AsyncProgramming #WebDevelopment #SoftwareEngineering #LearnInPublic
JS Macro vs Micro tasks: A debugging nightmare
More Relevant Posts
-
Extracting Types from Arrays Ever needed to get the type of items inside an array without rewriting it manually? You can achieve that with TypeScript as follows ⬇️. const statuses = ["active", "inactive", "pending"] as const; type Status = (typeof statuses)[number]; // "active" | "inactive" | "pending" That is because Arrays in JavaScript are actually objects with numeric keys, So [number] literally means: “Give me the type of whatever is stored at any index in this array.” It even works with arrays of objects: const tabs = [ { label: "Home", value: "/home" }, { label: "About", value: "/about" }, ]; type Tab = (typeof tabs)[number]; // { label: string; value: string; } 💡 This applies the Open/Closed Principle (OCP). #TypeScript #WebDevelopment #Frontend #CodingTips #JavaScript #LearnInPublic
To view or add a comment, sign in
-
-
👻 Undefined Ghost vs. Null Void 🚫 I spent too long to fix a bug today: my API sent `{ user: null }`, but my code checked for `undefined`! 🕵️♂️ The result? Unexpected crashes! 💥 🔑 Lesson: - `undefined` = not initialized, doesn’t exist yet - `null` = definitely empty, deliberately no value 👉 Remember: `null === undefined // false` `null == undefined // true` (better to avoid `==`!) Switching my check to `if (user === null)` made my code safer and bug-free. Ever got tripped up by a tiny JavaScript detail? Drop your story below! 👇 #JavaScript #NodeJS #MERNStack #WebDev #CodingTips #DevJourney
To view or add a comment, sign in
-
-
🚀 Day 9 of My 30 Days of JavaScript Journey ✅ Challenge: Arguments Length (LeetCode #2703) Write a function argumentsLength that returns the total number of arguments passed to it — no matter how many or what type! This challenge is a simple yet powerful way to understand rest parameters in JavaScript. 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/g8gK65Cp 💡 Solution: https://lnkd.in/gJQyNBaq 🧠 Concept Highlighted: This problem emphasizes the use of rest parameters (...args) to handle variable-length arguments, a handy feature for building flexible and reusable functions in JavaScript. #Day9 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #LearningEveryday #ProblemSolving #ES6
To view or add a comment, sign in
-
𝐀𝐥𝐥 𝐚𝐛𝐨𝐮𝐭 𝐡𝐨𝐰 𝐄𝐯𝐞𝐧𝐭 𝐋𝐨𝐨𝐩 𝐰𝐨𝐫𝐤𝐬 𝐢𝐧𝐭𝐞𝐫𝐧𝐚𝐥𝐥𝐲 𝐈𝐧 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 !! Understanding how JavaScript’s event loop works, especially with async/await, is a game changer for any developer. JavaScript doesn’t just run code line by line when async functions are involved. Instead, it uses something called the event loop, which manages different queues to decide what runs when. There are Microtasks (like promises and await) and Macrotasks (like setTimeout), and Microtasks always get priority. This means even when you use await, JavaScript pauses only inside that function but continues running other code outside it. That’s why sometimes console logs appear in unexpected orders! Grasping this helps you write better asynchronous code, avoid tricky bugs, and build smoother apps. Keep digging into these concepts — it’s worth it! In this post, I’m sharing everything you need to know about JavaScript’s event loop — explained in simple words. To make it even easier, I’ve created a set of slides that break down the concept step-by-step. Follow Gourav Roy for more such amazing content !! 𝐂𝐨𝐧𝐧𝐞𝐜𝐭 𝐨𝐧 𝐓𝐨𝐩𝐦𝐚𝐭𝐞 - https://lnkd.in/gyGxA7ut 𝐂𝐨𝐧𝐧𝐞𝐜𝐭 𝐨𝐧 𝐈𝐧𝐬𝐭𝐚𝐠𝐫𝐚𝐦 - https://lnkd.in/djMF2k3Q #JavaScript #EventLoop #AsyncAwait #WebDevelopment #CodingTips #Java
To view or add a comment, sign in
-
The JavaScript Event Loop — The Hidden Multitasking Hero If JavaScript is single-threaded, how does it look like it’s doing so many things at once? 🤔 Meet the Event Loop — the patient snake 🐍 that makes everything flow smoothly. 🧩 In simple words: JS runs one thing at a time (main thread). When async tasks finish, the Event Loop decides when to bring them back into action — like a patient teacher calling students one by one from different queues 😄 ✨ Takeaway: --> Promises (microtasks) always run before setTimeout (macrotasks). --> JS isn’t truly “multi-threaded” — it’s just a great illusionist. 🎩 Next up → 🧠 “this” Keyword — The Most Confused Owl in JavaScript 🦉 #JavaScript #EventLoop #AsyncJS #WebDevelopment #FrontendDevelopment #CodingCommunity #100DaysOfCode #LearnToCode #MERNStack #ProgrammingHumor
To view or add a comment, sign in
-
-
#TIL The “You Don’t Need” series is a great reality check for many long-lived JS habits. One of the classics: You don’t need Lodash anymore. Most of its utilities are now built into the language — Array.flatMap, Object.entries, String.replaceAll, and so on. And for teams who still want familiar APIs, there’s a modern alternative: ES Toolkit — smaller, faster, actively maintained, fully typed, and even Lodash-compatible. Resources worth checking: • https://lnkd.in/e_VkCk_Y • https://lnkd.in/e7wCZBQx • https://es-toolkit.dev/ Lodash/Underscore has served us well — but modern JS gives us cleaner, faster, and native ways to get the same job done. #JavaScript #Frontend #WebDevelopment #Performance #Tooling #YouDontNeedSeries
To view or add a comment, sign in
-
Going back to basics 🌱 What is JIT Compilation in Javascript ? We have already talked about how Javascript stores data and cleans memory. Now, let us see how it actually runs so fast......!!! Earlier, Javascript used an "interpreter" that executed code line by line simple, but not very fast... Modern "engines" like "V8" (used in Chrome and Node.js) use something smarter called "JIT Compilation"(Just in time Compilation). So it works something like this - 1. The "interpreter" starts running the code immediately. 2. The "JIT compiler" watches which parts run often. 3. It then converts those frequently used parts into "machine code" for faster execution. So, when the same code runs multiple times, Javascript optimises it, so the next executions happen much faster. #Javascript #Frontend
To view or add a comment, sign in
-
👋 Hello Connections! Hope you’re all doing great 😊 Today, I’d like to share something I learned... Stages of Errors in JavaScript. When working with JavaScript, we often face different types of errors, but not all errors are the same! Here are the three main stages of errors every developer should know: Syntax Error, Runtime Error, and Logical Error. 1.Syntax Error (Compile-Time): Occurs when your code has a syntax mistake — like missing brackets, commas, or incorrect keywords. Example:console.log("Hello World" **// missing parenthesis//** 2. Runtime Error (Execution-Time): Happens while the program is running for example, when you use an undefined variable or call a non-existing function. Example: let x = 10; console.log(y); **// y is not defined//** 3.Logical Error: The code runs without crashing, but the output is wrong due to incorrect logic. For Example: let num = 5; if (num = 10) { console.log("Number is 10"); } **//Wrong logic/output//** #JavaScript #WebDevelopment #ErrorHandling #10000coders #FresherJourney #TechLearning
To view or add a comment, sign in
-
-
How JS Converts [] + {} to [object Object] —🤯 JavaScript can be weirdly magical sometimes. Ever tried this in your console? 👇 [] + {} // Output: "[object Object]" At first glance, it looks confusing — why does an empty array and an empty object become a string? Let’s decode the magic 🪄 1️⃣ + Operator in JS The + operator doesn’t just add numbers — it can also concatenate strings. 2️⃣ Type Conversion Happens! [] (empty array) → when converted to string becomes "" (empty string). {} (empty object) → when converted to string becomes "[object Object]". 3️⃣ Final Expression So JS actually does: "" + "[object Object]" → "[object Object]" ✅ Bonus twist: Try reversing it: {} + [] Now it gives 0 because {} is treated as an empty block,not an object. 🤯 JavaScript — where logic meets magic ✨ 🔹 Follow Prashansa Sinha for more fun JS mysteries and simple explanations 👩💻 #JavaScript #WebDevelopment #Coding #Frontend #JS #LearnToCode #Programming #TechCommunity #Developers #CodeNewbie #WebDev
To view or add a comment, sign in
-
💻 Solving “Longest Common Prefix” on LeetCode (JavaScript Edition) Today I solved the “Longest Common Prefix” problem on LeetCode — a classic string challenge that’s simple on the surface but elegant when you find the right approach. 🧩 The challenge: Given an array of strings, return the longest prefix that’s common to all of them. Example: ["flower", "flow", "flight"] → "fl" ⚙️ My solution (JavaScript): Instead of checking every string one by one, I decided to sort the array first. This way, only the first and last words in sorted order need to be compared — because they’ll show the full range of differences in the array. 🧠 Why I like this approach: It’s clean and easy to reason about. Sorting reduces the comparison scope. It demonstrates how a small insight can simplify a problem significantly. 💬 Takeaway: Sometimes the most elegant solutions come from looking at the data differently — not from writing more code. #LeetCode #JavaScript #Coding #ProblemSolving #SoftwareEngineering #LearningJourney
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Anyone out there who had this kinda unlucky time? 🥴