One of the interesting questions asked in my interview was: ❓ “What are Microtasks and Macrotasks in JavaScript?” 💠 Understanding the Concept 🔹 JavaScript uses an event loop to handle asynchronous operations. 📌 Tasks are mainly divided into: 👉 Micro tasks : 🔹 High priority tasks 🔹 Executed immediately after the current synchronous code 🔹 Processed before macrotasks ✅ Examples: 🔹 Promise.then() 🔹 catch, finally 🔹 queueMicrotask() 👉 Macro tasks : 🔹 Lower priority compared to microtasks 🔸 Executed after microtasks queue is empty ✅ Examples: 🔹 setTimeout() 🔹 setInterval() 🔹 setImmediate() (Node.js) 🔄 Execution Order 🔹 Run synchronous code 🔹 Execute all microtasks 🔹 Execute one macrotask 🔹 Repeat This question tests understanding of Event loop, Asynchronous behavior and Execution order in JavaScript #JavaScript #EventLoop #AsyncProgramming #InterviewPrep #WebDevelopment #Learning #frontend #interviewExxperiance #interview
Microtasks vs Macrotasks in JavaScript
More Relevant Posts
-
🔒 Advanced JavaScript — Day 5: Scope, Execution Context & Closures Today I studied one of the most important — and most misunderstood — concepts in all of JavaScript. Closures. I've heard this word thrown around in interviews, tutorials, and job descriptions for months. Today I finally sat down, understood it deeply, and built a real project using it: a fully configurable Toast Notification system. Here's everything I covered 👇 📌 Scope — Where Variables Live 📌 Execution Context & the Scope Chain 📌 Closures — The Real Magic 🪄 📌 The Toast Project — What It Does 📌 Why Closures Matter in Real Development Today was one of those days where a concept that seemed complex finally clicked completely. Closures aren't magic. They're just functions that remember where they came from. Day 6 tomorrow. The streak continues. 🔥 #AdvancedJavaScript #JavaScript #Closures #Scope #ExecutionContext #100DaysOfCode #LearnInPublic #WebDevelopment #Frontend #CodingJourney #BuildInPublic #ProjectBased #TechLearning
To view or add a comment, sign in
-
-
🚀 Day 16 of My Frontend Interview Preparation Journey Today was all about strengthening JavaScript fundamentals 💪 🔹 Learned Event Delegation At first, I had a small confusion — I thought the listener bubbles up 😅 But today I understood the real concept: 👉 It’s the event that bubbles up, not the listener 👉 Event Delegation uses this behavior to handle child events from a parent 👉 This makes code more efficient and works even for dynamically added elements This concept really changed how I think about DOM events 🔥 🔹 Practiced let, var, const output-based questions Solved multiple tricky questions based on: Scope (block vs function) Hoisting behavior Temporal Dead Zone Re-declaration & re-assignment rules Realized that small differences in let, var, and const can completely change the output 🤯 💡 Key Learning: Understanding how JavaScript works internally is more important than just writing code. Every small concept is building confidence step by step 🚀 #JavaScript #FrontendDevelopment #InterviewPreparation #WebDevelopment #LearningInPublic
To view or add a comment, sign in
-
One of the most common JavaScript interview questions: "Why does setTimeout with 0ms delay not run immediately?" Most developers cannot answer this correctly. Here is the full explanation: JavaScript is single-threaded. It can only do one thing at a time. The Event Loop is how it manages everything else. The execution order is always the same: 1 — Synchronous code runs first All regular code on the Call Stack executes immediately. 2 — Microtasks run second Promises, async/await — these run before anything else once the Call Stack is empty. 3 — Macrotasks run last setTimeout, setInterval, DOM events — these wait until ALL microtasks are done. This is why setTimeout with 0ms still runs after a Promise. The Promise is a microtask. setTimeout is a macrotask. Microtasks always win. Understanding this prevents real bugs in production — async state updates, race conditions, unexpected render order. Save this post for your next async debugging session. Have you ever been confused by JavaScript async order? Drop a comment below. #JavaScript #WebDevelopment #Frontend #SoftwareEngineering #AsyncJavaScript
To view or add a comment, sign in
-
-
Day 17 of My Frontend Interview Preparation 🚀 Today I focused on one of the most important concepts in JavaScript — Prototype & Prototype Chaining. I learned how every object in JavaScript has a hidden link to another object (its prototype), and how JavaScript uses this chain to access properties and methods. This really helped me understand how things like arrays, functions, and objects share common behavior behind the scenes. Also cleared my confusion between __proto__ vs prototype — now it finally makes sense where each one is used 🙌 Along with this, I practiced several output-based questions, which helped me strengthen my understanding of tricky concepts and edge cases. 📌 Key Takeaways: How prototype works internally What is prototype chaining Difference between __proto__ and .prototype Improving problem-solving with output-based questions Slowly building strong fundamentals, one day at a time 💪 #Day17 #JavaScript #FrontendDevelopment #InterviewPreparation #WebDevelopment #CodingJourney
To view or add a comment, sign in
-
🚀 JavaScript Interview Question: Functions Today in my mock interview, I was asked: 👉 What is a function in JavaScript? 👉 How many types of functions are there? 👉 What is the syntax? ✅ What is a Function? A function in JavaScript is a reusable block of code designed to perform a specific task. It helps avoid repetition and makes code modular and organized. 📌 Types of Functions in JavaScript Function Declaration function greet() { console.log("Hello World"); } Function Expression const greet = function() { console.log("Hello World"); }; Arrow Function (ES6) const greet = () => { console.log("Hello World"); }; IIFE (Immediately Invoked Function Expression) (function() { console.log("Hello World"); })(); 💡 Why functions are important? ✔ Code reusability ✔ Better organization ✔ Easy debugging ✔ Cleaner and scalable code 📚 I’m currently learning JavaScript and improving my frontend development skills step by step. #JavaScript #FrontendDevelopment #ReactJS #WebDevelopment #MERNStack #LearningInPublic
To view or add a comment, sign in
-
In my previous blog, I explored String Polyfills and common interview methods — understanding how JavaScript works behind the scenes. Today, I went deeper into another fundamental concept: 👉 The new Keyword in JavaScript At first glance, it looks simple. But internally, it performs multiple steps that directly impact how objects, prototypes, and this behave. In this blog, I covered: ✔️ What the new keyword actually does ✔️ Step-by-step object creation process ✔️ How prototype linking works ✔️ Relationship between constructor and instances ✔️ Common mistakes (like forgetting new) And most importantly 👇 ⚠️ Confusing parts developers often struggle with: Array() vs new Array() Object creation patterns Constructor return behavior If you’re preparing for interviews or want to strengthen your JavaScript fundamentals, this will clear a lot of hidden concepts. 🔗 Read the full blog here: https://lnkd.in/grUGpMqe Next up in the series: JavaScript Modules (import/export) 🚀 #javascript #webdevelopment #frontenddeveloper #programming #softwaredevelopment #coding #100daysofcode #learninpublic
To view or add a comment, sign in
-
-
🚨 Stop scrolling if you keep forgetting JavaScript syntax. Ever blanked out on whether it’s .slice() or .substring()… Or struggled to recall a try...catch block during an interview? You’re not alone and that’s exactly why I created this 🚀 JavaScript Last-Minute Cheatsheet designed to save you hours of confusion and last-minute Googling. 💡 Inside the guide: ☑️ Essentials → Data types, operators, conditionals ☑️ Core Methods → Strings, Arrays, Math (with examples) ☑️ DOM Mastery → Select, create & update elements easily ☑️ Advanced JS → Promises, async/await, closures (simplified) Whether you're preparing for interviews or building real projects, this cheatsheet helps you revise faster & code with confidence. Follow M. WASEEM ♾️ for more valuable content #JavaScript #WebDevelopment #CodingCheatsheet #SoftwareEngineering #ProgrammingTips #LearnToCode #Developers #TechCommunity
To view or add a comment, sign in
-
Flattening arrays in JavaScript doesn’t have to be complicated 👇 Instead of writing long logic, just remember this: 🔹 Use flat(Infinity) 🔹 It converts nested arrays into a single-level array in one line. For interviews, knowing the recursive approach gives you an extra edge. #JavaScript #WebDevelopment #CodingTips #Frontend #LearnToCode
To view or add a comment, sign in
-
-
🚀 JavaScript Last-Minute Cheat Sheet — Perfect Before Interviews & Coding Rounds 🔥 Variables & Scope • "let" & "const" over "var" • Block scope matters • Avoid global variables ⚡ Functions • Arrow functions → shorter syntax • Default parameters save time • Closures = function + lexical scope 🧠 Async JavaScript • Callbacks → Promises → "async/await" • Use "try...catch" for error handling • "Promise.all()" for parallel execution 📦 Arrays & Objects • "map()", "filter()", "reduce()" = must know • Spread "..." & Destructuring simplify code • Optional chaining "?." prevents crashes 🎯 DOM & Events • "querySelector()" is your best friend • Event delegation improves performance • Debounce & throttle for optimization 💡 Pro Tip Understand concepts, not just syntax. Clean code + problem-solving mindset = real JavaScript mastery. Learn More From w3schools.com , JavaScript Mastery ✨ Follow ABDUL REHMAN ♾️ For More Usefull Contents 🔥 #JavaScript #WebDevelopment #FrontendDeveloper #CodingInterview #100DaysOfCode
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