✅ The 3 Types of Execution Context in JavaScript. 1️⃣ Global Execution Context (GEC) - Created when the JavaScript file first runs. - There is only one global execution context. - It creates: - Global object (window in browser) - this (which refers to window in browser) - Stays in the call stack until program finishes. 2️⃣ Function Execution Context (FEC) - Created every time a function is invoked. - Each function call gets its own execution context. - Pushed to the call stack. - Removed after function finishes. 3️⃣ Eval Execution Context (Rare / Advanced) - Created when code runs inside eval(). - Very rarely used in real production. - Avoided due to security and performance issues. Cheers, Binay 🙏 #javscript #developement #softwareengineering #frontend #buildinpublic #JSInternals #Programming #TechCareers #TechInterview
JavaScript Execution Contexts: GEC, FEC, and Eval
More Relevant Posts
-
The spread operator (...) is one of the most useful features in modern JavaScript. It allows you to copy and update arrays and objects in a clean and efficient way. In this short video, I explain: • How spread works with arrays • How values are copied instead of references • Adding new elements to arrays • Copying and updating objects • Why it is essential for immutability This concept is widely used in React for: • State updates • Props handling • Writing clean and maintainable code Understanding the spread operator is fundamental for frontend engineers. 👉 https://lnkd.in/gpc2mqcf 💬 Comment LINK and I’ll share the complete JavaScript roadmap. #JavaScript #ReactJS #FrontendEngineering #WebDevelopment #SoftwareEngineering #Programming #DeveloperEducation
Why Every React Developer Uses Spread Operator
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 Concepts Series – Day 5 / 30 📌 Hoisting in JavaScript 👀 Let’s Revise the Basics 🧐 Understanding Hoisting in JavaScript helps you know how variables and functions behave before execution. Hoisting means JavaScript moves declarations to the top of their scope during the memory creation phase. 🔹 var Hoisting Declared variables are hoisted Initialized with undefined Can be accessed before declaration (but value will be undefined) 🔹 let & const Hoisting Also hoisted But not initialized Stay in Temporal Dead Zone (TDZ) until declared Accessing before declaration → ReferenceError 🔹 Function Hoisting Function declarations are fully hoisted Can be called before declaration Function expressions are not hoisted like functions 💡 Key Insight var → Hoisted with undefined let & const → Hoisted but in TDZ Functions → Fully hoisted (only declarations) Understanding hoisting helps you avoid unexpected bugs and write predictable code execution flow. 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 Execution Demystified: The 3 Phases That Make Your Code Run 🚀.............. Before a single line executes, JavaScript performs a carefully orchestrated three‑phase journey. Parsing Phase scans your code for syntax errors and builds an Abstract Syntax Tree (AST)—if there's a typo, execution never starts. Creation Phase (memory allocation) hoists functions entirely, initializes var with undefined, and registers let/const in the Temporal Dead Zone (TDZ) while setting up scope chains and this. Finally, Execution Phase runs code line‑by‑line, assigns values, invokes functions, and hands off asynchronous tasks to the event loop. This three‑stage process repeats for every function call, with the call stack tracking execution and the event loop managing async operations. Master these phases to truly understand hoisting, closures, and why let throws errors before declaration! #javascript #webdev #coding #programming #executioncontext #parsing #hoisting #eventloop #js #frontend #backend #developer #tech #softwareengineering
To view or add a comment, sign in
-
-
🔄 The JavaScript Event Loop — most devs use it daily but can't explain it in an interview. Here's the simple truth: ➡️ JS is single-threaded — one task at a time. ➡️ The Call Stack runs your code synchronously. ➡️ Web APIs handle async tasks (setTimeout, fetch). ➡️ The Callback/Task Queue holds results waiting to run. ➡️ The Event Loop checks: "Is the stack empty? Push the next task." Example: console.log("1"); setTimeout(() => console.log("2"), 0); console.log("3"); // Output: 1, 3, 2 ← setTimeout goes to Web API, then queue Microtasks (Promises) run BEFORE the next macro task — that's why .then() beats setTimeout. Understanding this = writing faster, non-blocking code. 🚀 #JavaScript #WebDev #FullStack #Programming #SoftwareEngineering
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
-
-
Do you know why we use "() => {}" instead of "function () {}"? If you said "because it's shorter," you're only 10% right. In 2026, the real reason to choose one over the other is how they handle the this keyword. Understanding this distinction is what separates a Junior from an Engineer. Here is the 60-second breakdown: 𝟭. 𝗥𝗲𝗴𝘂𝗹𝗮𝗿 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀: 𝗧𝗵𝗲 "𝗖𝗼𝗻𝘁𝗲𝘅𝘁 𝗛𝘂𝗻𝘁𝗲𝗿𝘀" 🔍 Regular functions create their own this context. It changes based on 𝘩𝘰𝘸 the function is called. ● 𝗕𝗲𝘀𝘁 𝗳𝗼𝗿: Object methods or constructor functions. ● 𝗧𝗵𝗲 𝗖𝗮𝘁𝗰𝗵: In callbacks (like setTimeout), this might suddenly point to the Window object instead of your class. This is where those "undefined" bugs live! 𝟮. 𝗔𝗿𝗿𝗼𝘄 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀: 𝗧𝗵𝗲 "𝗖𝗼𝗻𝘁𝗲𝘅𝘁 𝗜𝗻𝗵𝗲𝗿𝗶𝘁𝗼𝗿𝘀" 🏹 Arrow functions don't have their own this. They "borrow" it from the code around them (Lexical Scoping). ● 𝗕𝗲𝘀𝘁 𝗳𝗼𝗿: React components, .map(), .filter(), and any callback where you want to keep the current context. ● 𝗧𝗵𝗲 𝗖𝗮𝘁𝗰𝗵: You cannot use new with them. They aren't meant to be constructors. 💡 𝗧𝗵𝗲 𝗦𝗲𝗻𝗶𝗼𝗿 𝗣𝗿𝗼-𝗧𝗶𝗽: Default to 𝗔𝗿𝗿𝗼𝘄 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀 for 95% of your modern JavaScript. Reach for a 𝗥𝗲𝗴𝘂𝗹𝗮𝗿 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻 only when you specifically need a dynamic this context. Clean code isn't just about syntax; it's about predictable behavior. 𝗪𝗵𝗶𝗰𝗵 𝗼𝗻𝗲 𝗱𝗼 𝘆𝗼𝘂 𝗳𝗶𝗻𝗱 𝘆𝗼𝘂𝗿𝘀𝗲𝗹𝗳 𝘂𝘀𝗶𝗻𝗴 𝗺𝗼𝗿𝗲 𝗼𝗳𝘁𝗲𝗻 𝗶𝗻 𝘆𝗼𝘂𝗿 𝗥𝗲𝗮𝗰𝘁 𝗽𝗿𝗼𝗷𝗲𝗰𝘁𝘀? 𝗟𝗲𝘁’𝘀 𝘁𝗮𝗹𝗸 𝘀𝗵𝗼𝗽 𝗶𝗻 𝘁𝗵𝗲 𝗰𝗼𝗺𝗺𝗲𝗻𝘁𝘀! 👇 #JavaScript #CodingTips #WebDevelopment #FrontendEngineer #Programming #CleanCode #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 JavaScript Concepts Series – Day 3 / 30 👀 Let's Revise the Basics🧐 Understanding the difference between var, let, and const is a fundamental concept in JavaScript. Choosing the right variable declaration helps prevent bugs and makes your code more predictable. 🔹 var Function scoped Can be redeclared Can be reassigned Hoisted (initialized with undefined) 🔹 let Block scoped Cannot be redeclared in the same scope Can be reassigned Hoisted but stays in Temporal Dead Zone (TDZ) until initialized 🔹 const Block scoped Cannot be redeclared Cannot be reassigned Must be initialized during declaration 💡 Key Insight var → Old way of declaring variables (function scoped) let → Use when the value may change const → Use when the value should not change Using let and const helps write safer and more maintainable JavaScript code. More JavaScript concepts coming soon. 🚀 #javascript #js #webdevelopment #frontenddeveloper #coding #programming #softwaredeveloper #developers #learnjavascript #javascriptdeveloper #codinglife #devcommunity #webdev #reactjs #mernstack #codingjourney #codeeveryday #techlearning #developerlife #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
Very informative