Hello, Tech Wizards 👋 🔥 JavaScript Coding Challenge – Day 6 | Event Loop Logic 🔥 What will be the output? console.log("Start"); setTimeout(() => { console.log("Timeout"); }, 0); Promise.resolve().then(() => { console.log("Promise"); }); console.log("End"); Think carefully about execution order. ✅ Answer: Start End Promise Timeout Why? 1️⃣ Synchronous code runs first → "Start" then "End" 2️⃣ Promises go to the microtask queue 3️⃣ setTimeout goes to the macrotask queue After the call stack is empty: Microtasks run first → "Promise" Then macrotasks → "Timeout" 📌 Concepts covered: Call Stack Microtask vs Macrotask Event Loop priority Most people assume setTimeout runs before Promise. It doesn’t. #JavaScript #FrontendDevelopment #WebDevelopment #CodingChallenge #100DaysOfCode #LearnInPublic #SoftwareDeveloper #TechCommunity #DeveloperJourney #WomenInTech
JavaScript Event Loop Logic Challenge: Execution Order
More Relevant Posts
-
🧠 JavaScript Closures — The Concept That Feels Confusing (Until It Clicks) Closures are not magic… they’re just how JavaScript remembers things. 👉 Definition: A closure is when a function “remembers” variables from its outer scope even after that outer function has finished executing. 💻 Example: function outer() { let count = 0; return function inner() { count++; console.log(count); }; } const counter = outer(); counter(); // 1 counter(); // 2 counter(); // 3 🤯 Why this works? Even though "outer()" is done, the "inner()" function still has access to "count". That’s a closure. 🔥 Real Use Cases: ✔ Data privacy (like private variables) ✔ Creating counters ✔ Maintaining state in functions ✔ Used heavily in React (hooks concept) 💡 Simple Way to Remember: 👉 “A function + its remembered environment = Closure” I learned this concept from 👉 Sheryians Coding School #javascript #frontend #webdevelopment #coding #developers #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 JavaScript Concepts Series – Day 6 / 30 📌 Closures in JavaScript 👀 Let’s Revise the Basics 🧐 A closure is when a function remembers variables from its outer scope even after the outer function has finished execution. 🔹 Key Points • Inner function can access outer variables • Data persists even after function execution • Useful for data privacy and state management 🔹 Example function outer() { let count = 0; return function inner() { count++; console.log(count); }; } const counter = outer(); counter(); // 1 counter(); // 2 💡 Key Insight Closure → Function + its lexical scope Remembers → Outer variables after execution Closures are widely used in callbacks, event handlers, and React hooks. More JavaScript concepts coming soon. 🚀 #javascript #js #webdevelopment #frontenddeveloper #coding #programming #developers #softwaredeveloper #learnjavascript #javascriptdeveloper #codinglife #devcommunity #webdev #reactjs #mernstack #codingjourney #codeeveryday #developerlife #100daysofcode #techlearning
To view or add a comment, sign in
-
-
🔥 JavaScript Closures Closures are everywhere in JavaScript… but often misunderstood. 👉 A closure is when a function remembers variables from its outer scope even after that function has finished. 💡 Example function outer() { let count = 0; return function () { count++; console.log(count); }; } const counter = outer(); counter(); // 1 counter(); // 2 👉 count is remembered — that’s a closure. Why it matters Closures help in: 1. Data privacy 2. Function factories 3. React hooks & event handlers ⚠️ Common Mistake Closures can cause unexpected bugs if you don’t understand them. Example: for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 1000); } 👉 Output: 3 3 3 Because var is function-scoped. Fix using let: for (let i = 0; i < 3; i++) { setTimeout(() => console.log(i), 1000); } 👉 Output: 0 1 2 Because let is block-scoped. #JavaScript #WebDevelopment #FrontendDevelopment #ReactJS #CodingConcepts #CleanCode #Developers #Programming #TechLearning #SoftwareDevelopment
To view or add a comment, sign in
-
🚀 Understanding Hoisting in JavaScript Many developers hear that JavaScript moves variables and functions to the top, but what actually happens behind the scenes? In JavaScript, hoisting occurs during the compilation phase, before the code executes. The JavaScript engine first scans the entire code and allocates memory for variables and functions. This means: • var variables are hoisted and initialized with undefined • let and const are also hoisted but remain in the Temporal Dead Zone (TDZ) until their declaration line is reached • Function declarations are fully hoisted, allowing them to be called before they appear in the code Example: console.log(a); var a = 10; Output: undefined Internally JavaScript treats it like this: var a; console.log(a); a = 10; ⚠️ Important: JavaScript does not physically move code to the top. During compilation the engine simply registers declarations in memory before execution begins. Understanding hoisting helps developers better grasp execution context, scope, and the JavaScript engine's behavior. #JavaScript #WebDevelopment #Frontend #Programming #Coding
To view or add a comment, sign in
-
JavaScript Closures — made simple 💡 Closures sound complex… but they’re actually simple once you get the idea. A closure is when a function remembers variables from its outer scope even after the outer function has finished executing. Think of it like this: An inner function carries a “backpack” of variables and never forgets them. How it works: 1. Outer function creates a variable 2. Inner function uses that variable 3. Outer function returns the inner function 4. Inner function still has access to that variable Why closures are powerful: • Data privacy (encapsulation) • Maintain state between function calls • Used in callbacks, event handlers, React hooks • Foundation for advanced JavaScript concepts Real-world uses: • Counters • Private variables • One-time execution functions • Custom hooks & memoization One-line takeaway: A closure = function with a memory of its lexical scope If you understand closures, you’re moving from basics to real JavaScript thinking. What concept in JavaScript took you the longest to understand? #JavaScript #Closures #WebDevelopment #Frontend #CodingConcepts #LearnJavaScript #Programming #DeveloperLife
To view or add a comment, sign in
-
-
JavaScript Closures — made simple 💡 Closures sound complex… but they’re actually simple once you get the idea. A closure is when a function remembers variables from its outer scope even after the outer function has finished executing. Think of it like this: An inner function carries a “backpack” of variables and never forgets them. How it works: 1. Outer function creates a variable 2. Inner function uses that variable 3. Outer function returns the inner function 4. Inner function still has access to that variable Why closures are powerful: • Data privacy (encapsulation) • Maintain state between function calls • Used in callbacks, event handlers, React hooks • Foundation for advanced JavaScript concepts Real-world uses: • Counters • Private variables • One-time execution functions • Custom hooks & memoization One-line takeaway: A closure = function with a memory of its lexical scope If you understand closures, you’re moving from basics to real JavaScript thinking. What concept in JavaScript took you the longest to understand? #JavaScript #Closures #WebDevelopment #Frontend #CodingConcepts #LearnJavaScript #Programming #DeveloperLife
To view or add a comment, sign in
-
-
Day 4 of 30 Days of JavaScript💻....#JavaScript30 Today’s focus was on working with some of the most powerful and commonly used JavaScript array methods: 1 . filter() Used to extract specific data from arrays based on conditions. 2 . map() Learned how to transform array data into a new format. 3 . sort() Sorted complex datasets like objects and strings alphabetically and numerically. 4 . reduce() Takes an array and reduces it into one final result. Through these exercises, I understood how JavaScript can process datasets efficiently using clean and readable functional-style code. Working through these concepts step by step is helping me strengthen my logic and gain more confidence in writing JavaScript, which will definitely support me in frontend development and problem solving. #JavaScript #WebDevelopment #LearningInPublic #CodingJourney #FrontendDevelopment #30DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 86 of My #100DaysOfCode Challenge Today I discovered a lesser-known feature in JavaScript — Symbols. Most developers work with object keys using strings, but JavaScript also provides another unique type called Symbol. A Symbol creates a unique and hidden property key that cannot accidentally conflict with other keys. Example const id = Symbol("id"); const user = { name: "Tejal", [id]: 12345 }; console.log(user.name); // Tejal console.log(user[id]); // 12345 Why Symbols are interesting • Every Symbol is unique • Helps create hidden object properties • Prevents accidental property overwriting • Often used internally in libraries and frameworks Even if two symbols have the same description, they are still different. const a = Symbol("key"); const b = Symbol("key"); console.log(a === b); // false Learning about features like Symbols helps me understand how JavaScript works behind the scenes and how large applications manage object data safely. Exploring deeper concepts every day. 💻✨ #Day86 #100DaysOfCode #JavaScript #WebDevelopment #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
Redux: Vanilla JavaScript https://lnkd.in/gspp_2MK A practical guide to implement Redux in Vanilla JavaScript, stripping away the complexity of frameworks to focus on core state management principles. Walking through the essential Redux workflow—Actions, Reducers, and the Store—demonstrating how to maintain a single source of truth in a web application. #ReactJS #reactjscourse #reactjsdeveloper #reactjsdevelopment #reactjstraining #codechallenge #programming #CODE #Coding #code #programmingtips #Redux #reduxredux
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