I thought JavaScript runs code line by line. It doesn't. Before executing a single line, the JS engine creates something called an Execution Context. Think of it like a stack of plates. Each function call adds a new plate on top. Last plate added is the first one removed. That's your Call Stack. Inside each execution context, two phases happen: Memory Phase — Variables are stored before code runs. var gets stored as undefined. let and const? They exist but are untouchable. That zone is called the Temporal Dead Zone. Execution Phase — Now the code actually runs. Values get assigned. Functions get called. I spent 4 years writing JavaScript. Never knew this was happening under the hood. Day 2. Still here. #JavaScript #BuildingInPublic #100DaysOfCode
JavaScript Execution Context Explained
More Relevant Posts
-
Writing Cleaner Code: Mastering Template Literals in JavaScript As developers, keeping our code readable is as important as making it functional. Traditional string concatenation can often lead to messy, hard-to-maintain code. In this quick tutorial, I demonstrate how Template Strings (Backticks) can: ✅ Simplify dynamic content injection. ✅ Handle multi-line strings effortlessly. ✅ Allow logic (like Ternary Operators) directly within the string. This simple switch makes your codebase much cleaner and more professional. Check out the demo in the video! #JavaScript #WebDevelopment #SoftwareEngineering #CodingBestPractices #CleanCode
To view or add a comment, sign in
-
I've been writing JavaScript for over a year. Thought I understood var, let, and const. I didn't. "var a" inside a block accessible outside. Prints "10". "let b" inside the same block, try to access it outside and you get: ReferenceError: b is not defined Same block. Same code. Completely different behavior. Turns out var lives in global memory. let and const get their own separate block scope. Once the block is done, they're gone. This is why going back to fundamentals matters #JavaScript #WebDev #LearnInPublic #NamasteJavaScript
To view or add a comment, sign in
-
-
Day 1 Js Depth Topic: JavaScript Execution context. - Execution Context is a special environment created when JavaScript code is evaluated and executed. There are two types of execution content: 1. GEC (Global execution context) - everything written outside the functions are are stored here for execution -like: 1.variable 2.function test 2. FEC (Function execution context) - created when functions are called for execution - with this we can call the js function before it even exists. - it is like calling your own box 🎁. finally it contains: 1. Variables 2. Functions 3. Scope 4. this keyword next will be the Scope chain 😄 stay tune with me in this journey. if I write anything wrong you can correct me. here to learn more
To view or add a comment, sign in
-
📚 Blog Series Update! Between projects and busy work hours, I spent some time this week working on Part 3 of my Rediscovering JavaScript series, and now I’m happy to share a new weekend read: Variables, Scope, and Memory 🚀 In this blog post, I explore some of the most important JavaScript fundamentals: 🔹 Primitive vs reference values 🔹 Scope and scope chain 🔹 Execution context 🔹 Memory management & garbage collection These topics may sound basic, but they explain many of the “why did this happen?” moments developers face while coding. 🔗 Part 3 Rediscovering JavaScript (Part 3): Variables, Scope, and Memory: https://lnkd.in/ek8CySJc 🔗Friend link: https://lnkd.in/e4ddDhSc ✨ For this journey, I’m using Professional JavaScript for Web Developers by Nicholas C. Zakas as my main guide. ☕ Wishing you a wonderful weekend and an enjoyable read with your coffee! #JavaScript #WebDevelopment #Frontend #Programming #SoftwareEngineering #DevTips #Medium
To view or add a comment, sign in
-
What will happen if you call a variable before initialization? 🤔 That is called Hoisting 👉 "JavaScript moves declarations to the top of their scope before execution" Sounds confusing? Let’s break it down 👇 When you create variables or functions, JavaScript runs your code in 2 phases: 1️⃣ Memory Creation Phase Before execution, JavaScript scans your code and allocates memory Example (mentally): var a → undefined let b → uninitialized (Temporal Dead Zone) 2️⃣ Execution Phase Now JavaScript runs your code line by line 👉 If you access variables before initialization: var → returns undefined let / const → ReferenceError Why does this happen? Because: var is initialized with undefined in memory let and const are hoisted but stay in the Temporal Dead Zone (TDZ) until the line where they are declared Simple way to remember: var => “exist, but don’t have a value yet” let / const => “Don’t touch before declaration” ⚡ Bonus: Function declarations are fully hoisted, so you can call them before defining them Curious how functions behave in hoisting? 🤔 Go Google function vs function expression in JavaScript — it’ll surprise you 👀 That’s hoisting in JavaScript 🚀 #javascript #webdevelopment #coding #frontend #learninpublic #hoisting
To view or add a comment, sign in
-
-
🧠 Day 3 of 21 days challenge JavaScript Event Loop 🤯 Event Loop is a mechanism in JavaScript that handles execution of asynchronous code. It continuously checks the call stack and callback queue. If the stack is empty, it moves tasks from the queue to the stack for execution. For example :- console.log("Start"); console.log("End"); console.log("Timeout"); Wait… why this order? Because JavaScript doesn’t run everything instantly. It uses: • Call Stack • Web APIs • Callback Queue Event Loop decides what runs next. 💤For easy understanding :- Event Loop = decides execution order Sync code runs first Async code waits in queue Then runs after the stack is empty 👉 That’s why “Timeout” runs last This changed how I understand async code 🚀 #JavaScript #EventLoop #Async
To view or add a comment, sign in
-
-
JavaScript performance tip: Use const and let instead of var. Why? → Block scoping prevents bugs → const signals immutability → Better for JS engines to optimize Small syntax change. Big impact on code quality. #JavaScript #BestPractices #Performance
To view or add a comment, sign in
-
𝗧𝗵𝗲 𝗝𝗮𝗩𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗥𝘂𝗻𝘁𝗶𝗺𝗲: 𝗙𝗶𝘅𝗶𝗻𝗴 𝗬𝗼𝘂𝗿 𝗠𝗲𝗻𝘁𝗮𝗹 𝗠𝗼𝗱𝗲𝗹 You may have noticed some behaviors in JavaScript that seem strange. For example: - setTimeout doesn't interrupt loops - setTimeout doesn't block - A resolved Promise still runs after synchronous code - await pauses a function but doesn't freeze the page - Rendering sometimes waits Let's explore why this happens. JavaScript executes synchronously inside a task. Nothing can interrupt that execution. Here's what we mean by 'synchronous' and 'asynchronous': - Synchronous execution: code that runs immediately, from top to bottom via the call stack - Asynchronous code: code whose result is not available immediately, it schedules something to run later Asynchronous mechanisms do not block nor interrupt the call stack. They arrange for something to run later via scheduling. Let's test this claim with a simple for loop and setTimeout: ``` is not allowed, so we use plain text instead console.log("sync start") for (let i = 0; i < 1e9; i++) {} console.log("sync end") console.log("sync start") setTimeout(() => { console.log("timeout fired") }, 0) for (let i = 0; i <
To view or add a comment, sign in
-
🚀 Dynamic Currying in JavaScript — Why it actually matters At first, currying feels like a trick: sum(1)(2)(3) But the real power isn’t syntax — it’s reusability. 💡 The idea 👉 Fix some arguments now 👉 Reuse the function later 🔧 Example const filter = fn => arr => arr.filter(fn); const filterEven = filter(x => x % 2 === 0); filterEven([1,2,3,4]); // [2,4] Instead of repeating logic everywhere, you create reusable building blocks. ⚡ Real-world uses API helpers → request(baseUrl)(endpoint) Logging → logger("ERROR")(msg) Event handlers → handleClick(id)(event) Validation → minLength(8)(value) 🧠 Key takeaway Currying isn’t about fancy functions. It’s about writing code that is: ✔ Reusable ✔ Composable ✔ Cleaner Libraries like Lodash and Ramda use this pattern heavily. Once this clicks, your approach to writing functions changes completely. #JavaScript #WebDevelopment #FunctionalProgramming #Currying #CleanCode #Frontend #Coding #100DaysOfCode #DeveloperJourney #TechCommunity
To view or add a comment, sign in
-
-
I built a browser-based code playground. Write HTML, CSS, and JavaScript on the left. See the result instantly on the right. No frameworks. No build tools. Just vanilla JavaScript. What it does: • Real-time preview as you type • Auto-saves your code • Tab key support for faster coding Live demo: https://lnkd.in/eXrHsNS2 #JavaScript #WebDevelopment #CodingTools Or even shorter: text Just shipped: Live Code Playground Write code → see results instantly. Auto-saves. Zero dependencies. Pure JS. Try it https://lnkd.in/eXrHsNS2
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