🚀 JavaScript Deep Dive — Part 2: Execution Context Ever wondered how JavaScript actually runs your code? 🤔 That’s done through something called an Execution Context — the environment where your code executes. 🧩 Types of Execution Context: 1️⃣ Global Execution Context (GEC) → Created once when the file runs. 2️⃣ Function Execution Context (FEC) → Created each time a function is called. ⚙️ Each has 2 Phases: 1. Creation Phase: Memory is set for variables & functions. Variables = undefined (hoisting). this keyword is set. 2. Execution Phase: Code runs line by line. Variables get real values. 💡 In short: JS runs code inside execution contexts, managed by a call stack — one at a time, top to bottom. #JavaScript #WebDevelopment #Frontend #LearnInPublic #Coding
Moniruzzaman Mahdi’s Post
More Relevant Posts
-
🔄 Day 164 of #200DaysOfCode Today, I revisited another classic JavaScript problem — removing duplicates from an array without using Set() or advanced methods. 💡 While there are modern one-liners that can handle this task in seconds, manually writing the logic helps build a deeper understanding of how arrays, loops, and conditions work together. This small challenge reinforced two key lessons: 1️⃣ Efficiency matters — Writing logic by hand makes you think about time complexity and performance. 2️⃣ Simplicity is strength — The most effective solutions are often the ones built from fundamental principles. 🔁 As developers, it’s not just about knowing shortcuts — it’s about understanding the why behind every concept. Revisiting such basic problems sharpens logical thinking and improves our ability to write cleaner, more optimized code. 🌱 Mastering the basics is not a step backward — it’s the foundation for everything advanced. #JavaScript #CodingChallenge #BackToBasics #164DaysOfCode #LearnInPublic #DeveloperMindset #WebDevelopment #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Understanding JavaScript Execution Context — The Foundation of How JS Runs! If you’ve ever wondered how JavaScript knows which variables and functions to access during code execution, the answer lies in the concept of Execution Context. An Execution Context is the environment where your code runs. It determines how and where variables, functions, and objects are stored and accessed. There are three main types: 1. 🌍 Global Execution Context (GEC): Created when your script first runs. It sets up the global object and this. 2. ⚙️ Function Execution Context (FEC): Created each time a function is called. Every function has its own execution environment. 3. 🧩 Eval Execution Context: Created when code runs inside eval() (rarely used). Each execution context goes through two phases: Creation Phase: Memory is allocated for variables and functions (hoisting happens here). Execution Phase: Code runs line by line, variables get their actual values, and functions are invoked. #JavaScript #WebDevelopment #Frontend #Coding #Learning #SDE #SoftwareEngineering #ReactJS
To view or add a comment, sign in
-
Remember those early days of JavaScript, when chaining multiple asynchronous operations felt like navigating a maze blindfolded? Callback hell was a rite of passage, and debugging felt like an archaeological dig. 🤔 I’ve definitely spent more than a few late nights trying to untangle nested callbacks. That experience taught me the true value of modern async patterns. The shift to 𝗣𝗿𝗼𝗺𝗶𝘀𝗲𝘀 was a game-changer for me. Suddenly, error handling became manageable, and composing operations felt intuitive. It brought so much 𝗰𝗹𝗮𝗿𝗶𝘁𝘆 to what was previously a jumbled mess. And then 𝗮𝘀𝘆𝗻𝗰/𝗮𝘄𝗮𝗶𝘁 arrived. This pattern transformed how I write asynchronous code, making it read almost like synchronous code. It significantly improves 𝗿𝗲𝗮𝗱𝗮𝗯𝗶𝗹𝗶𝘁𝘆 and reduces cognitive load, especially when dealing with sequential operations or conditional logic. I recall one project where we refactored a legacy API integration from deep callback nesting to async/await. The difference in maintainability was astounding. We cut debugging time by half. It reinforced that choosing the right async pattern isn't just about syntax; it’s about sustainable architecture. I’ll drop a simplified code example in the comments to illustrate what I mean. What's your preferred async pattern for complex JavaScript applications, and why? Share your lessons learned or any clever tricks you've picked up! #JavaScript #AsyncPatterns #WebDevelopment #SoftwareEngineering #TechLessons
To view or add a comment, sign in
-
-
💡 Execution Context vs. Scope Chain — Deep Dive in JS Ever wonder why a variable is accessible—because of where it was declared or because of what’s currently running? In JavaScript, the execution context is created when code runs (global, function, or eval). It holds things like this, the variable environment, and the lexical environment currently in use. The scope chain is the linked list of lexical environments the engine walks to resolve an identifier. Key idea: Lexical Environment = where code was defined. That’s why closures work—an inner function keeps a reference to the outer lexical environment, even after the outer function returns. Subtleties you’ll see in deep debugging: Shadowing: An inner let/const can shadow an outer name; the scope chain resolves the inner first. TDZ (Temporal Dead Zone): let/const exist in the lexical environment before initialization but are not readable—access throws. var hoisting: var binds to the function’s variable environment (not block), so it appears defined (with undefined) earlier than you expect. this is execution-context–dependent, not lexical—arrow functions capture this lexically; regular functions don’t. Rule of thumb: Name resolution is lexical; this is contextual. If this helped, drop a comment or follow for more JS deep dives! #JavaScript #WebDevelopment #CleanCode #Debugging #Frontend #NodeJS
To view or add a comment, sign in
-
-
🧠 JavaScript Concepts I Explored Today Today was a solid learning session — I spent time understanding how functions actually shape the logic in JavaScript. Here’s what I went through 👇 Functions and how they make code reusable First-class and higher-order functions (functions inside functions 🔁) Closures — the part where JS “remembers” variables even after execution IIFE — functions that run instantly (good for isolated scopes) Arrays — map, filter, reduce, forEach Objects — destructuring, looping, optional chaining These concepts connected so many dots for me. The more I write JavaScript, the more I realize how expressive it can be when you actually understand the “why” behind the syntax. #JavaScript #CodingJourney #WebDevelopment #Frontend #MERNStack
To view or add a comment, sign in
-
#Understanding JavaScript #Promises! Today, I learned about one of the most powerful concepts in JavaScript — Promises 🌟 A Promise is used for handling asynchronous operations. It represents the “eventual” completion (or failure) of a task and helps us avoid callback hell 😅 👉 Basic syntax: let promise = new Promise((resolve, reject) => { // async code here }) ✨ resolve() and reject() are callbacks provided by JavaScript to handle success or failure. Promises make code cleaner, more readable, and easier to manage — especially when combined with .then() and .catch(). #JavaScript #WebDevelopment #Promises #CodingJourney #LearningEveryday #FrontendDevelopment
To view or add a comment, sign in
-
-
🚀 #Day5Challenge – Deep Dive into Closures, Async/Await, Scopes & Lexical Environment. Today was all about connecting the dots between some of JavaScript’s most powerful (and tricky) concepts — Closures, Async/Await, Scopes, and the Lexical Environment. It’s the day where everything started to make sense. 🧠 🔹 Closures I explored how functions remember their outer variables — even after the parent function finishes execution. Closures taught me the real meaning of JavaScript’s memory behavior — how inner functions carry a reference to their outer scope, not just a copy. It’s the reason behind features like private variables, event handlers, and data encapsulation. 🔹 Lexical Environment & Scope I understood how each function forms its own lexical environment — a space where variables live and can be accessed by nested functions. Now I can clearly visualize how the scope chain works — how JS searches variables layer by layer (local → outer → global). No more confusion between block scope and function scope! 🔹 Async / Await Then came the twist — bringing Closures and Async/Await together! I learned how async functions still preserve their lexical scope while waiting for promises to resolve. Even when code execution pauses with await, the closure’s context remains intact — that’s how JavaScript ensures continuity and consistency. Today’s biggest win: “I stopped memorizing JavaScript behavior — and started understanding how it thinks.” #Day5Challenge #JavaScript #Closures #AsyncAwait #LexicalEnvironment #Scopes #FrontendDevelopment #WebDevelopment #CodingChallenge #JavaScriptLearning #AsyncJS #DeveloperJourney #CodeWithLogic
To view or add a comment, sign in
-
-
🚀 Decoding the Browser: How JavaScript Truly Executes! Today I explored how JavaScript executes inside the browser, and it was truly fascinating to understand the step-by-step process behind the scenes! 💡 (Check out the JIT compilation flow in the image!) Here’s what I learned 👇 1. The Synchronous Dance (JS Engine & JIT Compilation) Loading Phase: The browser starts by loading the HTML and identifies any <script> tags. Engine Hand-off: Once found, the code is sent to the JavaScript Engine (like Chrome’s V8). The Engine's Core Steps: ✨ Parsing: The engine first reads your code and converts it into an Abstract Syntax Tree (AST) 🎄. This is the structural map of your code. ⚙️ Interpretation: The Interpreter then quickly executes this AST, generating Bytecode. This ensures fast startup. ⚡ Just-In-Time (JIT) Compilation: For frequently executed code, the Optimizing Compiler steps in, transforming the Bytecode into highly efficient Machine Code for maximum performance. 🧩 Execution: The synchronous code runs on the Call Stack, while variables and objects are managed in the Memory Heap. 2. Mastering Asynchronous Operations (Event Loop) For asynchronous operations (set Timeout, fetch, etc.), the Web APIs, Callback Queue, and Event Loop beautifully coordinate to ensure non-blocking execution, keeping your UI responsive. 💬 In essence: HTML Parsing → JS Engine (Parsing + JIT Compilation) → Call Stack + Heap → Web APIs + Callback Queue + Event Loop → Execution Understanding this comprehensive flow is key to writing efficient, optimized, and clean JavaScript code that performs brilliantly. Excited to continue learning and sharing my progress each day under the guidance of Sudheer Velpula Sir. 🙌 #JavaScript #WebDevelopment #Frontend #LearningJourney #Coding #SudheerSir #10000coders
To view or add a comment, sign in
-
-
Diving into a core concept in JavaScript today: undefined and the Global Execution Context! Ever wondered why a newly declared variable in JS initially holds the value undefined? It's not magic, it's the meticulous work of the JavaScript engine! When your script first runs, the engine sets up the Global Execution Context. Think of this as the main environment for your code. It has two crucial phases: -Memory Creation Phase: Here, the engine scans your code for variable and function declarations. For every variable it finds, it allocates space in the memory component and automatically assigns the value undefined as a placeholder. -Code Execution Phase: Only then does the engine start running your code line by line, finally assigning actual values to your variables. So, undefined isn't just a random state; it's a deliberate signal from the engine that a variable exists but hasn't yet received its defined value during the execution flow. Understanding this helps demystify a lot of common JS behaviors! What are your thoughts on how JavaScript handles undefined? #JavaScript #WebDevelopment #Programming #ExecutionContext #Undefined #Memory #Code
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