🚀Day 3/100 #100DaysOfCode — JavaScript Core Foundations Today, I revised the fundamentals that actually control how JavaScript behaves under the hood. 🔹 Execution Context JavaScript runs in two phases inside the Global Execution Context: 1️⃣ Creation Phase Memory allocated var → initialized as undefined let & const → hoisted but placed in the Temporal Dead Zone (TDZ) 2️⃣ Execution Phase Code executes line by line Variables receive real values 🔹 var vs let vs const var is hoisted with undefined let & const are hoisted but inaccessible before declaration (TDZ) var allows re-declaration let & const do not var & let allow reassignment const does not var is function-scoped let & const are block-scoped 🔹 Arrow Functions Not hoisted like traditional functions No own this (inherits lexically) Cleaner implicit return const sum = (a, b) => a + b; 🔹 Rest & Spread Rest → collects remaining parameters into an array Spread → expands array elements 🔹 Destructuring Cleaner extraction from arrays & objects: let { name: myName, address: { city } } = person; Understanding execution context + scope is the foundation for closures, async JS, and advanced patterns. No shortcuts. Just depth. Day 4 tomorrow. #JavaScript #WebDev #IntermediateJS #CodingChallenge #Frontend #SoftwareEngineering #MERNStack #LearningEveryday
JavaScript Execution Context Fundamentals
More Relevant Posts
-
𝐋𝐞𝐭'𝐬 𝐞𝐱𝐩𝐥𝐨𝐫𝐞 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐚 𝐛𝐢𝐭😉 This question caught my attention with how simple it is, based on inference from my experience with JavaScript, and I thought to explain 𝗜𝘀 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗮 𝗱𝘆𝗻𝗮𝗺𝗶𝗰𝗮𝗹𝗹𝘆 𝘁𝘆𝗽𝗲𝗱 𝗼𝗿 𝘀𝘁𝗮𝘁𝗶𝗰𝗮𝗹𝗹𝘆 𝘁𝘆𝗽𝗲𝗱 𝗹𝗮𝗻𝗴𝘂𝗮𝗴𝗲? 𝐓𝐡𝐞 𝐚𝐧𝐬𝐰𝐞𝐫: JavaScript is dynamically typed. In dynamically typed languages, all type checks are performed at runtime, that is, when the program is executing. So this means you can assign anything to the variable and it will work. This is because types are associated with values, not variables. This flexibility is one of the reasons JavaScript became so popular. It allows developers to move quickly and write readable code. But it also introduces trade-offs. (Nothing really is for free😔) Because types are checked only at execution, certain mistakes only appear when the code runs. Some of which include: ☑ Unexpected type coercion ☑ Runtime errors ☑ Harder-to-maintain large codebases This is one of the reasons TypeScript gained popularity. Unlike JavaScript, TypeScript, a statically typed language, insists on all checks being performed during compile/build run before we execute our program. This allows developers to catch many type-related errors before the code runs. In the end, understanding JavaScript’s dynamic nature helps you: ☑ Write safer code ☑ Avoid subtle bugs ☑ Appreciate when tools like TypeScript are helpful #JavaScript #TypeScript #WebDevelopment #SoftwareEngineering #FrontendDevelopment
To view or add a comment, sign in
-
Most developers use JavaScript every day. Very few understand what actually happens behind the scenes. One of the most important fundamentals is this: 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐢𝐬 𝐬𝐢𝐧𝐠𝐥𝐞-𝐭𝐡𝐫𝐞𝐚𝐝𝐞𝐝. It can execute only one task at a time. Yet somehow it still handles network requests, timers, and user interactions smoothly. So what makes this possible? First, every function call enters the 𝐂𝐚𝐥𝐥 𝐒𝐭𝐚𝐜𝐤. This is where JavaScript executes code. If the stack is busy, nothing else can run. But asynchronous tasks like `setTimeout`, `fetch`, and DOM events don’t run inside the JavaScript engine itself. They are handled by 𝐁𝐫𝐨𝐰𝐬𝐞𝐫 𝐖𝐞𝐛 𝐀𝐏𝐈𝐬. Once those operations finish, their callbacks move into the 𝐂𝐚𝐥𝐥𝐛𝐚𝐜𝐤 𝐐𝐮𝐞𝐮𝐞. Then the 𝐄𝐯𝐞𝐧𝐭 𝐋𝐨𝐨𝐩 steps in. It constantly checks whether the Call Stack is empty. When it is, tasks from the queue are pushed into the stack for execution. That simple cycle is what enables asynchronous behavior—even in a single-threaded language. Understanding this mental model makes development much easier: * Debug async issues by visualizing the call stack and queue * Use `async/await` confidently once you understand promises * Avoid blocking operations that freeze the event loop Once this concept clicks, JavaScript suddenly feels far less mysterious. When did the 𝐄𝐯𝐞𝐧𝐭 𝐋𝐨𝐨𝐩 finally make sense to you? #JavaScript #WebDevelopment #FrontendEngineering #EventLoop #AsyncProgramming #SoftwareEngineering #ProgrammingFundamentals #MERNStack
To view or add a comment, sign in
-
-
🚀 Understanding the JavaScript Event Loop While learning JavaScript, one concept that really changed how I think about asynchronous code is the Event Loop. JavaScript is single-threaded, which means it can execute only one task at a time. But thanks to the Event Loop, it can still handle asynchronous operations like API calls, timers, and user interactions without blocking the main thread. Here’s the simple flow: 1️⃣ Code enters the Call Stack 2️⃣ Async tasks go to Web APIs 3️⃣ Their callbacks move to the Callback Queue 4️⃣ The Event Loop checks if the Call Stack is empty 5️⃣ Then it pushes the callback into the Call Stack for execution This mechanism is what allows JavaScript to remain non-blocking and highly efficient. Understanding the Event Loop helped me write better asynchronous code using Promises, async/await, and callbacks. If you're learning JavaScript, mastering the Event Loop is a must! 💡 #JavaScript #EventLoop #WebDevelopment #AsyncJavaScript #CodingJourney #FrontendDevelopment
To view or add a comment, sign in
-
-
Today JavaScript humbled me again 😭 I thought I understood async JS… but then the Event Loop said “bro sit down.” We explored the chaotic squad behind the scenes: 🧵 Call Stack – the overworked intern running the code 🌀 Event Loop – the manager deciding who gets attention ⚡ Microtask Queue – the VIP lane (Promises, queueMicrotask, process.nextTick) ⏳ Macrotask Queue – the waiting room (setTimeout, setInterval, setImmediate) Biggest plot twist of the day 👇 You write: setTimeout(fn, 0) and think: “Nice… this will run immediately.” JavaScript: “Haha… no.” Because JS first clears the Call Stack, then executes Microtasks, and only then checks Macrotasks. So the real priority is: Call Stack → Microtasks → Macrotasks Which explains why JavaScript sometimes feels like it's gaslighting you during console.log outputs 💀 Huge thanks to Devendra Dhote Bhaiya for explaining this so clearly. Really fun session and lots of brain upgrades today 🧠⚡ JavaScript is basically: “Single-threaded… but emotionally multi-threaded.” #JavaScript #EventLoop #AsyncJavaScript #WebDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
🧠 Ever wondered how JavaScript keeps track of which function is running? JavaScript uses something called the Call Stack. Think of it like a stack of tasks where functions are added and removed as they execute. 🔹 How the Call Stack Works JavaScript follows a Last In, First Out (LIFO) rule. That means: The last function added to the stack is the first one to finish. Example function first() { second(); } function second() { third(); } function third() { console.log("Hello from third function"); } first(); What happens in the Call Stack 1️⃣ first() is pushed to the stack 2️⃣ second() is called → pushed to the stack 3️⃣ third() is called → pushed to the stack 4️⃣ third() finishes → removed from stack 5️⃣ second() finishes → removed 6️⃣ first() finishes → removed 🔹 Visualising the Stack Call Stack at peak: - third() - second() - first() - Global() Then it unwinds back to the Global Execution Context. 💡 Why This Matters Understanding the call stack helps you understand: - Execution order - Stack overflow errors - Debugging JavaScript - Async behaviour It’s one of the core mechanics of the JavaScript engine. Next post: The Event Loop 🚀 #JavaScript #CallStack #Frontend #WebDevelopment #LearnJS #Programming #LearningInPublic
To view or add a comment, sign in
-
-
Things I wish someone had drawn out for me when I was starting with JavaScript. A lot of engineers write JS for years without really knowing what happens after they hit run. How does the code actually execute? What's the JS engine doing? Why does async code behave the way it does? Why does setTimeout sometimes feel unpredictable? It all makes sense once you see the full picture. Here's what these notes cover: The JS Runtime Environment — engine, call stack, memory heap, and how execution contexts are created and destroyed. The Event Loop, how it continuously monitors the call stack and decides what runs next. Callback Queue vs Microtask Queue, why Promises behave differently from setTimeout, and why microtasks always go first. JIT Compilation, how V8 interprets and optimises your code on the fly. Web APIs and the Browser, where setTimeout, DOM APIs, fetch, and localStorage actually live. Once this clicked for me, a lot of "weird" JavaScript behaviour stopped feeling weird. If you're learning JS right now, save this. Come back to it when async starts feeling confusing. What part of JavaScript took you the longest to truly understand? #JavaScript #WebDevelopment #Frontend #LearnToCode
To view or add a comment, sign in
-
-
⚡ Understanding the JavaScript Event Loop (Simplified) One concept that helped me understand JavaScript much better is the Event Loop. JavaScript is single-threaded, but it can still handle asynchronous operations like API calls, timers, and promises. How? Because of the Event Loop. In simple terms: 1️⃣ JavaScript executes synchronous code first (Call Stack). 2️⃣ Async tasks like setTimeout or API requests go to Web APIs. 3️⃣ Once completed, they move to the Callback Queue. 4️⃣ The Event Loop checks if the call stack is empty and pushes callbacks back for execution. This is why code like this works: console.log("Start"); setTimeout(() => { console.log("Async Task"); }, 0); console.log("End"); Output: Start End Async Task Even with 0 delay, async tasks wait until the call stack is empty. 💬 When did you first learn about the Event Loop? #JavaScript #WebDevelopment #FrontendDevelopment #AsyncProgramming
To view or add a comment, sign in
-
🚨 Ever wondered what actually happens behind the scenes when your JavaScript code runs? Or why some variables behave like they exist before you even write them? 🤯 Let’s break it down — because understanding this changes how you write JavaScript forever. 👇 💡 Execution Context in JavaScript Every time your JS code runs, it goes through two powerful phases: 🔹 1. Memory Creation Phase (a.k.a Variable Environment) • JavaScript scans your code before execution • Allocates memory for variables and functions • Variables are initialized with undefined • Functions are stored with their entire definition 👉 This is why hoisting happens! 🔹 2. Code Execution Phase (Thread of Execution) • Code runs line by line • Variables get their actual values assigned • Functions are invoked and executed • A single thread handles everything (yes, JS is single-threaded!) ⚡ Important Insight JavaScript doesn’t just “run code” — it prepares and then executes. That preparation step is what often confuses developers. 😬 Common Confusion • Accessing variables before assignment → undefined • Thinking JS executes top-to-bottom only → not entirely true • Misunderstanding hoisting → leads to bugs 🔥 Pro Tip Mastering execution context helps you: • Debug faster • Write predictable code • Truly understand closures, scope, and async behavior 📌 Think of it like this: Memory Creation = Setting the stage 🎭 Execution Phase = Performing the play 🎬 Once you see it this way, JavaScript starts making a lot more sense. #JavaScript #WebDevelopment #AsyncProgramming #Coding #LearnToCode #100DaysOfCode
To view or add a comment, sign in
-
-
✨ 𝗗𝗮𝘆 𝟭𝟳 𝗼𝗳 𝗠𝘆 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 🚀 Today I explored one of the most important concepts in JavaScript: the 𝗘𝘃𝗲𝗻𝘁 𝗟𝗼𝗼𝗽. I learned why 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗶𝘀 𝘀𝗶𝗻𝗴𝗹𝗲-𝘁𝗵𝗿𝗲𝗮𝗱𝗲𝗱 𝗮𝗻𝗱 𝘀𝘆𝗻𝗰𝗵𝗿𝗼𝗻𝗼𝘂𝘀, yet still capable of handling asynchronous tasks efficiently. Key ideas I understood: 🔹 𝗦𝗶𝗻𝗴𝗹𝗲-𝘁𝗵𝗿𝗲𝗮𝗱𝗲𝗱 𝗻𝗮𝘁𝘂𝗿𝗲 – JavaScript runs one task at a time on a single call stack. 🔹 𝗦𝘆𝗻𝗰𝗵𝗿𝗼𝗻𝗼𝘂𝘀 𝗲𝘅𝗲𝗰𝘂𝘁𝗶𝗼𝗻 – code runs line by line by default. 🔹 𝗘𝘃𝗲𝗻𝘁 𝗟𝗼𝗼𝗽 – manages asynchronous operations by coordinating the 𝗖𝗮𝗹𝗹 𝗦𝘁𝗮𝗰𝗸, 𝗪𝗲𝗯 𝗔𝗣𝗜𝘀, 𝗮𝗻𝗱 𝗖𝗮𝗹𝗹𝗯𝗮𝗰𝗸 𝗤𝘂𝗲𝘂𝗲. This concept finally helped me understand how JavaScript handles things like 𝘁𝗶𝗺𝗲𝗿𝘀, 𝗲𝘃𝗲𝗻𝘁𝘀, 𝗮𝗻𝗱 𝗮𝘀𝘆𝗻𝗰𝗵𝗿𝗼𝗻𝗼𝘂𝘀 𝗼𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻𝘀 without blocking the main thread. #JavaScript #100DaysOfCode #WebDevelopment #LearningJourney #FrontendDevelopment #EventLoop
To view or add a comment, sign in
-
-
Today I explored one of the most confusing but fascinating concepts in JavaScript — The Event Loop. JavaScript is single-threaded, but it still handles asynchronous tasks like API calls, timers, and promises smoothly. The magic behind this is the Event Loop. Here’s the simple flow: 1️⃣ Call Stack – Executes synchronous code 2️⃣ Web APIs – Handles async tasks (setTimeout, fetch, DOM events) 3️⃣ Callback Queue / Microtask Queue – Stores callbacks waiting to execute 4️⃣ Event Loop – Moves tasks to the call stack when it’s empty 💡 Example: console.log("Start"); setTimeout(() => { console.log("Timeout"); }, 0); Promise.resolve().then(() => { console.log("Promise"); }); console.log("End"); 🧠 Output: Start End Promise Timeout Why? Because Promises go to the Microtask Queue which runs before the Callback Queue. ✨ Learning this helped me finally understand how JavaScript manages async behavior without multi-threading. Tomorrow I plan to explore another interesting JavaScript concept! Devendra Dhote Ritik Rajput #javascript #webdevelopment #frontenddeveloper #100DaysOfCode #learninginpublic #codingjourney #sheryianscodingschool
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