Day 179: Peeling Back the JavaScript Layers 🧅 Today was all about moving beyond "how to code" and diving into how JavaScript actually works under the hood. I spent the day dissecting objects, the prototype chain, and the evolution of asynchronous patterns. 🧬 The Prototype Power I finally stopped looking at __proto__ as a mystery and started seeing it as a roadmap. Understanding how objects inherit properties from their parents—and how we can extend built-in objects with custom methods like getTrueLength()—is a total game-changer for writing dry, efficient code. ⏳ The Async Evolution: Escaping "Hell" We’ve all seen it: the pyramid of doom known as Callback Hell. Today, I practiced refactoring those nested messes into clean Promises and eventually into the sleek, readable Async/Await syntax. It's not just about making the code work; it's about making it readable for the "future me." 👯 Shallow vs. Deep Copy One of the most important lessons today was realizing that the Spread Operator (...) isn't a magic wand for copying. Shallow Copy: Quick and easy, but nested objects are still linked to the original. Deep Copy: Using JSON.parse(JSON.stringify()) to completely sever ties and create a truly independent clone. Key takeaways: Object Mastery: Using Object.values() and hasOwnProperty to navigate data safely. Array Essentials: Re-mastering map, reduce, and Array.from(). The 'New' Keyword: Understanding how it establishes that hidden link to the constructor's prototype. If you’re not understanding the prototype chain, you’re only using 50% of JavaScript’s power! #100DaysOfCode #JavaScript #WebDevelopment #CodingJourney #SoftwareEngineering #AsyncJS #Prototypes #BuildInPublic
Unlocking JavaScript's Power: Prototype Chain Mastery
More Relevant Posts
-
🚀 Day 75 — Visualizing the JavaScript Call Stack Today I learned how JavaScript actually executes code behind the scenes using something called the Call Stack. Understanding this completely changed how I think about function execution. 🧠 What is the Call Stack? The Call Stack is a mechanism used by JavaScript to keep track of function execution. 👉 JavaScript is single-threaded, meaning it executes one task at a time. So whenever a function runs, it is added to the stack. 🔹 How It Works Think of it like a stack of plates: ✅ New function → placed on top ✅ Function finished → removed from top This follows the rule: LIFO (Last In, First Out) 🔍 Example function third() { console.log("Third function"); } function second() { third(); console.log("Second function"); } function first() { second(); console.log("First function"); } first(); ⚙ Execution Flow (Step by Step) 1️⃣ first() added to Call Stack 2️⃣ second() added 3️⃣ third() added 4️⃣ third() executes → removed 5️⃣ second() executes → removed 6️⃣ first() executes → removed Finally → Stack becomes empty ✅ 📌 Why Call Stack Matters Understanding Call Stack helps explain: ✅ Function execution order ✅ Debugging errors ✅ Stack Overflow errors ✅ Infinite recursion problems ✅ Async behavior understanding ⚠ Example of Stack Overflow function repeat() { repeat(); } repeat(); Since the function never stops, the stack keeps growing until: ❌ Maximum Call Stack Size Exceeded 💡 Key Learning JavaScript doesn’t randomly run code. Every function waits its turn inside the Call Stack, making execution predictable and structured. Understanding this made debugging much easier for me. #Day75 #JavaScript #CallStack #WebDevelopment #LearningInPublic #DeveloperJourney
To view or add a comment, sign in
-
-
The tale of two dots: Mastering the difference between Spread vs. Rest in JavaScript. 🧐 If you are learning modern JavaScript, the three dots syntax (...) can be incredibly confusing. Depending on where you place them, they either act as the Spread operator or the Rest operator. They look identical, but they do complete opposite jobs. Here is the simplest way to differentiate them. ✅ 1. The Spread Operator (The "Unpacker") Think of Spread as opening a suitcase and dumping everything out onto the bed. It takes an iterable (like an array or an object) and expands it into individual elements. Common Use Cases: Copying arrays/objects (shallow copies). Merging arrays/objects together. Passing elements of an array as separate arguments into a function. ✅ 2. The Rest Operator (The "Gatherer") Think of Rest as taking leftovers on a table and putting them all into one Tupperware container. It does the opposite of spread. It collects multiple separate elements and condenses them into a single array or object. Common Use Cases: Handling variable numbers of function arguments. Destructuring arrays or objects to grab "the rest" of the items. 💡 The Golden Rule to Tell Them Apart It’s all about context. Look at where the dots are used: If it’s used in a function call or on the right side of an equals sign, it’s usually Spread (it's expanding data). If it’s used in a function definition or on the left side of an equals sign (destructuring), it’s usually Rest (it's gathering data). Which one do you find yourself using more often in your daily work? #JavaScript #WebDevelopment #CodingTips #SoftwareEngineering #Frontend
To view or add a comment, sign in
-
-
Stop Mutating Your State! 🛑 Understanding Deep Copy vs. Shallow Copy in JavaScript As JavaScript developers, we often run into "ghost bugs" where updating one object accidentally changes another. This happens because of how JavaScript handles References. The Pitfall: Shallow Copying Using the spread operator (...) is great for simple, flat objects, but it only performs a "shallow" copy. If your object contains nested objects or arrays, the references to those nested items are still shared between the original and the copy. The Solution: Modern Deep Copy In the past, we relied on JSON.parse(JSON.stringify(obj)) which is slow and fragile or external libraries like Lodash. Today, we have a superior, built-in solution: structuredClone(). Why should you switch to structuredClone()? Predictable State: Essential for frameworks like React where immutability is key. Clean Code: No more "Spread Hell" where you manually spread five nested levels just to update one property. Performance: It is a native browser API, highly optimized, and handles complex data types natively. (See the code snippet below for the direct comparison!) How are you handling complex state updates in your projects? Are you still using the spread operator for everything, or have you fully adopted structuredClone? Let’s discuss in the comments! 🚀 #JavaScript #WebDevelopment #ReactJS #CleanCode #FullStack #SoftwareEngineering #ProgrammingTips #webdevelopment #programming #TechFuture
To view or add a comment, sign in
-
-
🚀 JavaScript Tip: var vs let vs const — Explained Simply Understanding how variables work in JavaScript can save you from hard-to-debug issues later. Think of variables as containers that hold values ☕ 🔹 var – Old Style (Not Recommended) ➡️ Function scoped ➡️ Can be re-declared & reassigned ➡️ Gets hoisted → may cause unexpected bugs 👉 Use only if maintaining legacy code 🔹 let – Modern & Safe ➡️ Block scoped {} ➡️ Cannot be re-declared ➡️ Can be reassigned ➡️ Hoisted but protected by Temporal Dead Zone 👉 Best for values that change over time 🔹 const – Locked & Reliable ➡️ Block scoped {} ➡️ Cannot be re-declared or reassigned ➡️ Must be initialized immediately 👉 Best for fixed values and cleaner code ✅ Best Practice Use const by default, switch to let only when reassignment is needed, and avoid var 🚫 💡 Small fundamentals like these make a big difference in writing clean, scalable JavaScript. #JavaScript #WebDevelopment #FrontendDevelopment #ProgrammingTips #LearnJavaScript #CodingBestPractices #DeveloperLearning #SoftwareEngineering #100DaysOfCode
To view or add a comment, sign in
-
-
🧠 The Call Stack in JavaScript — Simplified JavaScript executes code using something called the call stack. It follows one simple rule: Last In, First Out (LIFO). Every time a function runs, it gets pushed onto the stack, and when it finishes, it gets popped off. Understanding this small concept makes debugging errors like “Maximum call stack size exceeded” much easier. It also helps you truly understand recursion and how JavaScript executes code step by step. Read more here 👉 https://lnkd.in/g2CCpCqs #JavaScript #WebDevelopment #Programming
To view or add a comment, sign in
-
🚀Day 3/100 #100DaysOfCode — JavaScript Core Foundations Today, I revised the fundamentals that actually control how JavaScript behaves under the hood. 🔹 Execution Context JavaScript runs in two phases inside the Global Execution Context: 1️⃣ Creation Phase Memory allocated var → initialized as undefined let & const → hoisted but placed in the Temporal Dead Zone (TDZ) 2️⃣ Execution Phase Code executes line by line Variables receive real values 🔹 var vs let vs const var is hoisted with undefined let & const are hoisted but inaccessible before declaration (TDZ) var allows re-declaration let & const do not var & let allow reassignment const does not var is function-scoped let & const are block-scoped 🔹 Arrow Functions Not hoisted like traditional functions No own this (inherits lexically) Cleaner implicit return const sum = (a, b) => a + b; 🔹 Rest & Spread Rest → collects remaining parameters into an array Spread → expands array elements 🔹 Destructuring Cleaner extraction from arrays & objects: let { name: myName, address: { city } } = person; Understanding execution context + scope is the foundation for closures, async JS, and advanced patterns. No shortcuts. Just depth. Day 4 tomorrow. #JavaScript #WebDev #IntermediateJS #CodingChallenge #Frontend #SoftwareEngineering #MERNStack #LearningEveryday
To view or add a comment, sign in
-
🚀 JavaScript Magic: Why "Undefined" is actually a Feature, not a Bug! I just had a "Wow" moment diving into the JavaScript Execution Context, and it changed how I look at my code. Ever wondered why you can console.log a variable before you even declare it, and JavaScript doesn't lose its mind? 🤯 🧠 The Secret: Two-Phase Execution When your code runs, JavaScript doesn't just start at line 1. It takes two passes: 1.Memory Creation Phase: JS scans your code and allocates space for all variables and functions. 2. Execution Phase: It runs the code line-by-line. ⚡ The var Behavior (Hoisting) If you use var, JavaScript initializes it as undefined during the memory phase. Result: You can log it early. No error, just a quiet undefined. It’s like the variable is there, but its "suit" hasn't arrived yet. 🛑 The let & const Twist (TDZ) Try the same thing with let or const, and the engine throws a ReferenceError. Why? The Temporal Dead Zone (TDZ). While let and const are also "hoisted," they aren't initialized. They stay in a "dead zone" from the start of the block until the moment the code actually hits the declaration. The Lesson: JavaScript isn't just reading your code; it's preparing for it. Understanding the Execution Context makes debugging feel like having X-ray vision. 🦸♂️ Have you ever been bitten by the Temporal Dead Zone, or do you still find yourself reaching for var out of habit? Let’s discuss! 👇 #JavaScript #WebDevelopment #CodingTips #Frontend #Programming101
To view or add a comment, sign in
-
“JS Fundamentals Series #1: Execution Context & Call Stack” Behind every line of JavaScript lies a hidden world of execution contexts and stacks — let’s uncover it 👇 Whenever a JavaScript program runs, the JS engine creates a Global Execution Context (GEC), a Global Object, and a special this variable. Think of the Execution Context as a big container with two parts: 1. Memory Component 2. Code Component 🔄 The whole JavaScript code gets executed in two phases:- 1. Memory creation phase: All the variables and functions are assigned memory in the form of "key: value" pairs inside the Memory Component. Variables are assigned a special keyword called "undefined" until their value is initialized. Functions are assigned their whole body as it is. 2. Code execution phase: Inside Code Component, each piece of code gets executed, only one command will get executed at a time and won't move onto the next until the current command is executed. Whenever a function is called/invoked, a new Local Execution Context is created inside the Code Component. 📚 Call Stack This is where all the Execution Contexts are executed in a particular order. It follows a principle known as LIFO - Last In First Out. 💡 Why this matters: Understanding the call stack helps me debug recursion errors, async issues, and write cleaner, more predictable code. 🚀 Next up: I’ll dive into Scope Chain & Lexical Environment. Stay tuned! #JavaScript #Frontend #WebDevelopment #NamasteJS #LearningJourney
To view or add a comment, sign in
-
-
𝗧𝗵𝗲 𝗝𝗮 v𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗘𝗫𝗲𝗰𝘂𝘁𝗶𝗼𝗻 𝗖𝗼𝗻𝘁𝗲𝗫𝘁 You write code and hit "run". But what happens next? The JavaScript engine creates an Execution Context. This is the environment where your code runs. It holds variables, functions, and the scope chain. Think of it as a container that stores everything your code needs. The engine pre-scans your code before running it. It allocates memory, sets variables to undefined, and maps out the scope chain. Then it runs your code line by line. Here's an example: ``` is not allowed, so let's describe it: You have a variable devName and two functions: startSprint and displayTask. When startSprint is called, it creates a new context. When displayTask is called, it creates another context. The Call Stack is like a to-do list. It's a last-in, first-out structure. When a function finishes, its context is removed from the stack. Understanding the Execution Context helps you debug your code. It explains how closures work and how to improve performance. You can think of the Global Context like the main branch of your repo. Function contexts are like feature branches or sandboxes. The Execution Context is the key to understanding JavaScript. It's the "why" behind many weird behaviors. Once you understand it, debugging becomes easier. Source: https://lnkd.in/ghTAE-4q
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