Today I learned one of the most important core concepts in JavaScript – Execution Context. Earlier, JavaScript execution felt like “magic” to me. After understanding Execution Context, I now clearly know how JavaScript reads, stores, and executes code behind the scenes. How JavaScript creates an Execution Context before running any code The two phases: Memory Creation Phase and Code Execution Phase Difference between Global Execution Context and Function Execution Context How the Call Stack manages function execution How variables and functions are allocated memory before execution Understanding this concept made me realize that JavaScript is not just about writing code, but about understanding how the engine thinks and processes instructions. 1.Memory Creation Phase: var x = 10; function greet() {} In memory: x → undefined greet → function reference 2.Code Execution Phase Global Context #JavaScript #ExecutionContext #CallStack #WebDevelopment #FrontendDevelopment #LearningJourney
Understanding JavaScript Execution Context
More Relevant Posts
-
DAY-1 About JS execution 📍How JavaScript Executes Code Ever wondered HOW JavaScript runs your code? 🤔 Before executing even a single line, JavaScript does something very important 👇 👉🏽 Step 1: Global Execution Context (GEC) is created When a JS program starts, the JS engine creates the Global Execution Context. It has two phases: 1️⃣ Memory Creation Phase (Hoisting) Allocates memory for: Variables → undefined Functions → full function definition Example: var x = 10; function example() { console.log("Hello"); } In memory: x → undefined example → function 2️⃣ Code Execution Phase Executes code line by line Assigns actual values x → 10 example() → executed when called 🔹 What does GEC contain? ✅ Memory / Variable Environment ✅ Thread of Execution ✅ this keyword (points to window in browsers) 🔹 Important point to remember 🧠 JavaScript is synchronous & single-threaded ➡️ Executes one line at a time ➡️ One execution context at a time #JavaScript #JSexecution #FrontendDevelopment #FullStackDevelopment #DSA #MachineCoding
To view or add a comment, sign in
-
🤔 Quick question: If JavaScript is single-threaded, why does it feel asynchronous? When I first learned that JS runs on a single thread, this confused me a lot. How can one thread handle timers, promises, and user events? Turns out… JavaScript isn’t doing this alone 👇 console.log("Start"); setTimeout(() => { console.log("Timeout"); }, 0); console.log("End"); Output: Start End Timeout 💡 What’s really happening? - JavaScript executes synchronous code first - setTimeout is offloaded to Web APIs - Once the call stack is empty, the callback is pushed back for execution - This makes JavaScript feel asynchronous, even though it’s single-threaded Takeaway - JavaScript itself is single-threaded. - Asynchronous behavior comes from the runtime environment (browser / Node.js) and the event loop, not from JS running multiple threads. #JavaScript #WebDevelopment #FullStack #LearningInPublic
To view or add a comment, sign in
-
JavaScript is single-threaded… Yet it handles asynchronous operations without blocking the main thread. Here’s what most developers don’t fully understand 👇 • res.json() returns a Promise because reading and parsing the response body is asynchronous. • Arrow functions don’t have their own this — they inherit it from the surrounding (lexical) scope. • map() returns a new array because it transforms each element, while forEach() doesn’t return anything — it simply executes logic for each item. • Promises don’t make code asynchronous — they help manage the result of asynchronous operations. • The event loop is what enables non-blocking behavior in JavaScript. Revisiting concepts like callbacks, promise chaining, async/await, error handling, APIs, JSON, HTTP verbs, prototypes, and inheritance made one thing clear: Understanding how JavaScript works internally changes how you write code. What JavaScript concept took you the longest to truly understand? 👇 #JavaScript #AsyncJavaScript #WebDevelopment #FullStackDevelopment #MERNStack #SoftwareDeveloper
To view or add a comment, sign in
-
-
you'd definitely be using JS if you are a developer, but do you know how it's executed? Let’s see how JavaScript internally works 🚀 Before any line of JavaScript is executed, the JS engine creates something called the Global Execution Context. This is the starting point of JavaScript execution. Global Execution Context has 3 main parts: 1️⃣ Memory Component (Variable Environment) Memory is allocated for variables and functions. It scans the variables and store them before execution but assigns value on execution. This is called hoisting. var → undefined function declarations → stored completely Do let and const hoist? yes, for let / const - memory is allocated but not accessible (Temporal Dead Zone) 2️⃣ Code Component (Execution Thread) This is where JavaScript executes the code line by line. Here the variables are assigned their values, function calls are executed, etc. 3️⃣ this keyword In the global context: Browser → window Node.js → global 💡 In simple terms: GEC is the foundation on which JavaScript runs. Understand this, and concepts like hoisting, scope, and errors start making sense automatically. Did you find it interesting? #JavaScript #globalExecutionContext #learning #internalWorking
To view or add a comment, sign in
-
-
🚀 Hello everyone, lets understand Scope in JavaScript: One of the most powerful — yet often misunderstood — concepts in JavaScript is scope. It defines where your variables and functions are accessible, and mastering it can make the difference between clean, bug-free code and hours of debugging chaos. 🔑 Types of Scope in JavaScript: ▪️ Global Scope: Variables declared outside any function/block are accessible everywhere. Great for constants, but risky if overused. ▪️ Function Scope: Variables declared inside a function are only accessible within that function. This keeps logic self-contained. ▪️ Block Scope (ES6): With let and const, variables declared inside {} are limited to that block. This prevents accidental leaks into outer code. ▪️ Lexical Scope: Outer scope variables are accessible inside inner functions, but Inner scope variables are not accessible outside their block/function. 💡 Why Scope Matters? ▪️ Prevents naming conflicts ▪️ Improves readability and maintainability ▪️ Helps avoid unintended side effects ▪️ Encourages modular, reusable code 👉Always prefer let and const over var. They respect block scope and make your code more predictable. Share your thoughts on this and rectify me wherever I'm wrong. Let’s share and learn together. #JavaScript #WebDevelopment #Scope #ES6 #CodingTips #DeveloperCommunity #TechInsights
To view or add a comment, sign in
-
🗓️ Day 61/100 – Understanding the JavaScript Scope Chain Today I finally understood why sometimes variables work… and sometimes they suddenly don’t. The answer = Scope Chain At first I thought JavaScript just “searches everywhere” for a variable. But no — it actually follows a very specific path. JavaScript looks for variables in this order: 1️⃣ Current function scope 2️⃣ Parent function scope 3️⃣ Global scope It climbs upward step-by-step until it finds the variable. This is called the scope chain. --- Example idea: A function inside a function inside a function… The inner function can access outer variables But the outer function cannot access inner variables So access flows inside → outside Never outside → inside --- Big realization today 💡 Most bugs I faced earlier were not logic mistakes… They were scope mistakes. If you understand scope chain: • Closures make sense • Hoisting becomes clearer • Debugging becomes easier JavaScript stops feeling random — It starts feeling predictable. Slowly the language is revealing its rules, not magic. #100DaysOfCode #JavaScript #Scope #WebDevelopment #Frontend #LearningInPublic
To view or add a comment, sign in
-
-
📌 JavaScript concat() Method – Explained Simply The concat() method in JavaScript is used to merge two or more arrays or strings and return a new combined result — without modifying the original data. 👉 Key Characteristics 🔹 Does not mutate the original array or string 🔹 Returns a new array or string 🔹 Preserves the order of elements 🔹 Can accept multiple arguments 👉 Why use concat()? 🔹 Ideal when you want to combine data safely 🔹 Helps maintain immutability, which is important in React and modern JavaScript 🔹 Makes code cleaner and more readable For arrays, concat() is often preferred over push() when you don’t want to change the original array. 🔁 Immutability leads to predictable and bug-free code. #JavaScript #WebDevelopment #Frontend #JSMethods #CleanCode #Learning
To view or add a comment, sign in
-
-
🚀 Event Loop Deep Dive — How JavaScript Really Executes Your Code Most developers use async JavaScript every day… but very few truly understand how it actually works under the hood. JavaScript is single threaded, yet it handles: • API calls • timers • promises • user interactions So what’s the secret? 👉 The Event Loop I just published a deep-dive article where I break this down step by step: ✔ How JavaScript executes synchronous code ✔ What really happens inside the Call Stack ✔ Global Execution Context explained visually ✔ Microtasks vs Macrotasks (Promises vs setTimeout) ✔ Why execution order surprises even experienced devs No shortcuts. No magic. Just how JavaScript really works. If you’ve ever been confused by execution order or faced weird async bugs this one’s for you. 📖 Read the full article here: 🔗 https://lnkd.in/dbUCv6N5 #JavaScript #EventLoop #WebDevelopment #Frontend #SoftwareEngineering #AsyncJS #React #NodeJS
To view or add a comment, sign in
-
Why JavaScript Isn’t Truly Asynchronous We often say JavaScript is asynchronous. Technically… it’s not. JavaScript is single-threaded and synchronous. Async behavior comes from the environment (Web APIs) and the event loop. • Code runs on the call stack • Async tasks move to Web APIs • Completed tasks go to a queue • The event loop pushes them back when the stack is free Understanding this changed how I think about async logic — especially in React. Still diving deeper into callbacks, promises, and the event loop.
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