🚀 Day 10 of My JavaScript Journey ✨Today I explored how JavaScript actually works behind the scenes — and honestly, it changed the way I look at code completely 🤯 Here’s what I learned 👇 🧠 How JavaScript Code RunsJavaScript doesn’t just execute line by line — it first creates an Execution Context which manages everything. ⚙️ Execution Context Phases1️⃣ Memory Allocation Phase Variables get stored with undefined Functions are stored completely 2️⃣ Execution Phase Code runs line by line Values get assigned and functions execute 📦 Call Stack & Execution Flow JavaScript uses a Call Stack to manage function calls Each function creates its own execution context Stack follows LIFO (Last In, First Out) 💾 Stack vs Heap Memory Stack → Stores primitive values (fast ⚡) Heap → Stores objects (reference-based 🧩) 🤖 Interpreter BehaviorJavaScript reads and executes code step by step using an interpreter — not compiled like some other languages. ❓ Why undefined Appears?Because during memory phase, variables are declared but not initialized yet. ⬆️ Hoisting Explained var is hoisted with undefined Functions are fully hoisted let & const are hoisted but stay in Temporal Dead Zone (TDZ) ❌ 🚫 Temporal Dead Zone (TDZ)You can’t access let & const variables before initialization — it throws an error. ⚠️ Function Expressions vs Hoisting Function declarations → hoisted ✅ Function expressions → behave like variables ❌ 💡 Key TakeawayUnderstanding execution context, memory, and hoisting makes debugging WAY easier and helps write cleaner code 🔥 📌 Slowly moving from writing code → to understanding how it actually works inside #JavaScript #WebDevelopment #MERNStack #CodingJourney #LearnToCode #FrontendDevelopment #DeveloperLife
JavaScript Execution Context and Hoisting Explained
More Relevant Posts
-
🚀Day 30 — Scope Chain & Scope Types in JavaScript (Simplified) Understanding scope is one of the most important fundamentals in JavaScript 🚀 --- 🔍 What is Scope? 👉 Scope decides where variables can be accessed in your code In simple words: 👉 “Who can access what?” --- ⚡ Types of Scope 1. Global Scope 👉 Variables declared outside functions or blocks let name = "John"; function greet() { console.log(name); // accessible } --- 2. Function Scope 👉 Variables declared inside a function function test() { let age = 25; console.log(age); } console.log(age); // ❌ Error --- 3. Block Scope 👉 Variables declared with let and const inside {} if (true) { let city = "Delhi"; } console.log(city); // ❌ Error --- 🔗 What is Scope Chain? 👉 If JS can’t find a variable in current scope, it looks in the outer scope, then outer again… until global scope. This is called the Scope Chain --- 🚀 Why it matters ✔ Prevents variable conflicts ✔ Helps understand closures ✔ Improves debugging skills --- 💡 One-line takeaway: 👉 “JavaScript looks upward to find variables — that’s the scope chain.” --- Mastering scope makes closures, hoisting, and debugging much easier. #JavaScript #Scope #ScopeChain #WebDevelopment #Frontend #100DaysOfCode 🚀
To view or add a comment, sign in
-
🚀 Day 5 — Understanding JavaScript Hoisting & Execution Context Missed sharing yesterday’s update, so posting it today 👇 Continuing my journey of strengthening core JavaScript fundamentals, I explored one of the most important (and commonly asked) concepts in interviews — how JavaScript actually runs behind the scenes. 🔹 Covered topics: - JavaScript Hoisting: • Variables and functions can be used before declaration • Only declarations are hoisted, not initializations • Difference in behavior: var vs let vs const - Temporal Dead Zone (TDZ): • Why let & const throw errors before initialization • Understanding “Cannot access before initialization” - Execution Context (🔥 very important): • How JavaScript executes code internally • Two phases: - Memory Creation Phase - Execution Phase - Memory Creation Phase: • Variables stored as undefined • Functions stored completely - Execution Phase: • Code runs line by line • Values get assigned and functions executed - Function Hoisting: • Function declarations are fully hoisted • Function expressions behave differently - Call Stack: • How JavaScript manages function execution (LIFO) 💡 Key Learning: JavaScript is not executing code line-by-line directly — it first scans and prepares memory, then executes. 👉 Concepts like: - Why var gives undefined but let/const throw error - How execution context is created - How functions are stored and executed - What happens internally before a single line runs These are core interview concepts that define how deeply you understand JavaScript. This phase is helping me move from just writing code → to understanding how JavaScript engine actually works internally ⚡ 📌 Day 5 of consistent preparation — building strong fundamentals step by step 🔥 #JavaScript #WebDevelopment #FullStackDeveloper #CodingJourney #MERNStack #InterviewPreparation #Frontend #Backend #LearnInPublic #Developers #LinkedIn #Consistency #Connections
To view or add a comment, sign in
-
🧠 JavaScript Hoisting Explained Simply Hoisting is one of those JavaScript concepts that can feel confusing — especially when your code behaves unexpectedly. Here’s a simple way to understand it 👇 🔹 What is Hoisting? Hoisting means JavaScript moves declarations to the top of their scope before execution. But there’s a catch 👇 🔹 Example with var console.log(a); var a = 10; Output: undefined Why? Because JavaScript internally treats it like: var a; console.log(a); a = 10; 🔹 What about let and const? console.log(b); let b = 20; This throws a ReferenceError. Because "let" and "const" are hoisted too — but they stay in a “temporal dead zone” until initialized. 🔹 Function hoisting Functions are fully hoisted: sayHello(); function sayHello() { console.log("Hello"); } This works because the function is available before execution. 🔹 Key takeaway • "var" → hoisted with "undefined" • "let/const" → hoisted but not initialized • functions → fully hoisted 💡 One thing I’ve learned: Many “weird” JavaScript bugs come from not understanding hoisting properly. Curious to hear from other developers 👇 Did hoisting ever confuse you when you started learning JavaScript? #javascript #frontenddevelopment #webdevelopment #reactjs #softwareengineering #developers
To view or add a comment, sign in
-
-
🚀 How JavaScript Works Behind the Scenes We use JavaScript every day… But have you ever thought about what actually happens when your code runs? 🤔 Let’s understand it in a simple way 👇 --- 💡 Step 1: JavaScript needs an Engine JavaScript doesn’t run on its own. It runs inside a JavaScript engine like V8 (Chrome / Node.js). 👉 Engine reads → understands → executes your code --- 💡 Step 2: Two Important Things When your code runs, JavaScript uses: 👉 Memory Heap → stores variables & functions 👉 Call Stack → executes code line by line --- 💡 Step 3: What happens internally? let name = "Aman"; function greet() { console.log("Hello " + name); } greet(); Behind the scenes: - "name" stored in Memory Heap - "greet()" stored in Memory Heap - function call goes to Call Stack - executes → removed from stack --- 💡 Step 4: Single Threaded Meaning JavaScript can do only one task at a time 👉 One Call Stack 👉 One execution at a time --- ❓ But then… how does async work? (setTimeout, API calls, promises?) 👉 That’s handled by the runtime (browser / Node.js) More on this in next post 👀 --- 💡 Why this matters? Because this is the base of: - Call Stack - Execution Context - Closures - Async JS --- 👨💻 Starting a series to revisit JavaScript from basics → advanced with focus on real understanding Follow along if you want to master JS 🚀 #JavaScript #JavaScriptFoundation #WebDevelopment #FrontendDevelopment #Coding #SoftwareEngineer #Tech
To view or add a comment, sign in
-
-
🚀 From Tricky to Clear — My JavaScript Practice Journey🚀 💡Today I worked on a couple of problems that initially felt tricky, but after breaking them down step by step, I was able to solve them completely. 💡 🔹 Problem 1: String to Object Conversion I learned how to transform a string into meaningful key-value pairs by grouping characters and mapping them into an object. 👉 This improved my understanding of: • String manipulation • Index-based iteration • How data can be structured dynamically 🔹 Problem 2: Rearranging Array (Positive & Negative) This problem was more challenging. I worked on separating positive and negative numbers and then merging them in a specific pattern. 👉 Key takeaways: • Logical thinking and pattern recognition • Handling multiple arrays efficiently • Using loops to control data flow step by step ✨ What I realized: At first, these problems looked confusing, but once I broke them into smaller parts, they became much easier to solve. Consistent practice is really helping me improve my problem-solving skills. #JavaScript #ProblemSolving #CodingJourney #FrontendDevelopment #LearningInPublic
To view or add a comment, sign in
-
🍃 Gist of some minutes of the day - 9th April 2026 ❓ What happens behind simple JavaScript code? Since I got into the basics of JavaScript—scope and variables—I have noticed one thing. Maybe it's late to notice, yet I’m interested in going deeper. It's just that in any JavaScript program, if you get an error in the middle or at any other line, the remaining lines of code won't get executed. ❓ Why won't it get executed if an error occurs? It's because JavaScript follows a single-threaded execution model. ❓ Then, I got another question, What if JavaScript needs to handle many more tasks? Yes! It can, by using: ---> Call Stack + Web APIs + Callback Queue + Event Loop ❓ Next, I raised another question - What do all these do and how? Simply, when there is a task that takes time to execute and makes other tasks wait, JavaScript uses Web APIs. These Web APIs make the task wait by using an OS timer or other mechanisms, allowing other tasks to execute. Once the timer finishes, JavaScript moves the function to the Callback Queue. If there exists a function or task, then it executes it. Here, the Web API won't hold a single line of code that has to wait. It holds the task. A simple example is given in the image. That’s a simple code snippet to understand what happens and how JavaScript can handle multiple things. It can be applied to concepts such as fetching APIs or other browser-related tasks. ⏳ Behind the scenes: ▪️ It sends the task to the Web API to hold it ▪️ JavaScript becomes free ▪️ Then it executes the next tasks ▪️ Once completed, it goes to the Callback Queue ▪️ It checks if there is a function to be executed ▪️ Then executes it if it exists I still have more questions, and I would like to receive more questions from anyone interested in diving deeper. It may seem easy, but the concept behind it is deep and interesting. Meet you all later with explorable info, With Universe, Swetha. #JavaScript #SelfLearn #Basics #FoundationalValue
To view or add a comment, sign in
-
-
Day 4/100 of JavaScript 🚀 Today’s focus: Functions in JavaScript Functions are reusable blocks of code used to perform specific tasks Some important types with example code: 1. Parameterized function → takes input function greet(name) { return "Hello " + name; } greet("Apsar"); 2. Pure function → same input always gives same output, no side effects function add(a, b) { return a + b; } add(2, 3); 3. Callback function → function passed into another function function processUser(name, callback) { callback(name); } processUser("Apsar", function(name) { console.log("User:", name); }); 4.Function expression → function stored in a variable const multiply = function(a, b) { return a * b; }; 5.Arrow function → shorter syntax const square = (n) => n * n; Key understanding: Functions are first-class citizens in JavaScript — they can be passed, returned, and stored like values #Day4 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
I’ve started learning scope in JavaScript, but before diving into it, I took an interesting detour into a very important question: Is JavaScript compiled or interpreted? Before getting into scope properly, I learned that JavaScript does not behave like a simple line-by-line interpreter. A good example is this: ```js console.log("Hello"); function foo() { console....log("world"); } console.log("hello world"); ``` If JavaScript was executed in a purely naive line-by-line way, we might expect "Hello" to be logged before the error appears. But that does not happen. The script fails before execution starts because the JavaScript engine first goes through an initial preparation phase. That phase includes things like: 1. parsing the code 2. checking whether the syntax is valid 3. building an internal representation 4. preparing the code for execution So a better mental model is: Source code -> Parse / syntax check -> Internal representation / compilation steps -> Execution This helped me understand that calling JS simply “interpreted” is not the full picture. Modern JavaScript engines like V8 are much more advanced. They can parse code, create internal representations, interpret some code, compile parts into bytecode or internal instructions, and even JIT-compile frequently used parts for better performance. So JavaScript is commonly called an interpreted language, but in modern engines, the reality is more nuanced. This also connects nicely with scope. Scope is about the visibility of variables and functions in code, but before JavaScript can execute code, the engine first needs to understand the structure of that code. That means scope is not just a runtime topic. It is closely connected to how the engine reads, parses, and prepares the program. My main takeaway: JavaScript is not random, and it is not just “reading one line at a time”. There is a preparation phase before execution, and understanding that makes topics like scope, hoisting, and errors much easier to reason about. #JavaScript #TypeScript #WebDevelopment #SoftwareEngineering #V8 #LearningInPublic
To view or add a comment, sign in
-
-
🧠 JavaScript Scope & Lexical Scope Explained Simply Many JavaScript concepts like closures, hoisting, and this become much easier once you understand scope. Here’s a simple way to think about it 👇 🔹 What is Scope? Scope determines where variables are accessible in your code. There are mainly 3 types: • Global Scope • Function Scope • Block Scope (let, const) 🔹 Example let globalVar = "I am global"; function test() { let localVar = "I am local"; console.log(globalVar); // accessible } console.log(localVar); // ❌ error 🔹 What is Lexical Scope? Lexical scope means that scope is determined by where variables are written in the code, not how functions are called. Example 👇 function outer() { let name = "Frontend Dev"; function inner() { console.log(name); } inner(); } inner() can access name because it is defined inside outer(). 🔹 Why this matters Understanding scope helps you: ✅ avoid bugs ✅ understand closures ✅ write predictable code 💡 One thing I’ve learned: Most “confusing” JavaScript behavior becomes clear when you understand how scope works. Curious to hear from other developers 👇 Which JavaScript concept clicked for you only after learning scope? #javascript #frontenddevelopment #webdevelopment #reactjs #softwareengineering #developers
To view or add a comment, sign in
-
Explore related topics
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