𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗦𝗵𝗮𝗹𝗹𝗼𝘄 𝗖𝗼𝗽𝘆 𝘃𝘀 𝗗𝗲𝗲𝗽 𝗖𝗼𝗽𝘆 📦 If you’ve ever updated state and something weird happened… this might be why 👇 🔹 Shallow Copy → copies only the first level 🔹 Nested objects are still referenced (same memory) Example: ➡️ Using { ...obj } or Object.assign() 💡 Problem: Change a nested value… and you might accidentally mutate the original object 😬 🔹 Deep Copy → copies everything (all levels) 🔹 No shared references 🔹 Safe to modify without side effects Example: ➡️ structuredClone(obj) ➡️ or libraries like lodash ⚠️ The common pitfall: You think you made a copy: ➡️ { ...user } But inside: ➡️ user.address.city is STILL linked So when you update it: ❌ You mutate the original state ❌ React may not re-render correctly ❌ Bugs appear out of nowhere 🚀 Why this matters (especially in React): State should be immutable ➡️ Always create safe copies ➡️ Avoid hidden mutations ➡️ Keep updates predictable 💡 Rule of thumb: 🔹 Flat objects? → shallow copy is fine 🔹 Nested data? → consider deep copy Understanding this difference = fewer bugs + cleaner state management And yes… almost every developer gets burned by this at least once 😄 Sources: - JavaScript Mastery - w3schools.com Follow 👨💻 Enea Zani for more #javascript #reactjs #webdevelopment #frontend #programming #coding #developers #learnjavascript #softwareengineering #100DaysOfCode
👨💻 Enea Zani’s Post
More Relevant Posts
-
𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗠𝗮𝗽() 𝘃𝘀 𝗙𝗼𝗿𝗘𝗮𝗰𝗵() 🔥 Confused about when to use map() and when to use forEach()? Here’s the difference that every JavaScript developer should know 👇 🔹 forEach() → executes a function for every element 🔹 It does NOT return a new array 🔹 Mainly used for side effects (logging, API calls, DOM updates) Example: ➡️ arr.forEach(item => console.log(item)) 🔹 map() → also loops through every element 🔹 BUT returns a brand new array 🔹 Perfect for transforming data Example: ➡️ const names = users.map(user => user.name) ⚠️ The common mistake: Using forEach() when you actually need transformed data 😬 Example: ❌ const result = arr.forEach(item => item * 2) Why? Because forEach() returns: ➡️ undefined Correct way: ✅ const result = arr.map(item => item * 2) 💡 Simple rule: Need a new array? ➡️ use map() Need to just “do something” with each item? ➡️ use forEach() That small difference can save you from weird bugs and messy code. 🚀 Understanding this = cleaner logic + better interviews + stronger JavaScript fundamentals If you're learning JS, React, or preparing for technical interviews… this is essential. 📚 Sources: • JavaScript Mastery • w3schools.com Follow for more: 👨💻 Enea Zani #javascript #webdevelopment #frontend #reactjs #coding #developers #programming #100DaysOfCode #learnjavascript #softwareengineer
To view or add a comment, sign in
-
-
⚡ Lecture 2: Advanced Array Methods You’re Probably Misusing 🔹 Title: JavaScript Array Methods You Think You Know (But Don’t) 🔹 Post Content: Most developers use array methods. Very few understand them. Let’s go deeper: 1️⃣ find() vs filter() const users = [{id:1}, {id:2}, {id:3}]; const user = users.find(u => u.id === 2); 👉 Returns ONE object const usersList = users.filter(u => u.id === 2); 👉 Returns ARRAY Rule: Need one result? → find() Need multiple? → filter() 2️⃣ some() & every() – Boolean Logic const nums = [2,4,6]; nums.some(n => n > 5); // true nums.every(n => n > 1); // true Insight: These replace messy conditional loops. 3️⃣ includes() – Cleaner Checks const fruits = ["apple", "banana"]; fruits.includes("apple"); // true Stop writing unnecessary loops. 🚨 Brutal Truth: If your code has too many loops, you're not thinking functionally. 📌 Final Thought: Clean code isn’t about fewer lines — it’s about better logic. 🔖 Hashtags: #JavaScriptTips #CleanCode #WebDev #ProgrammingLife #FrontendDeveloper #CodeBetter
To view or add a comment, sign in
-
-
Today was one of those days where things finally clicked While working on one of my ongoing projects, I built a VS Code–like File Explorer from scratch in React — and it turned out to be a great learning experience. Here’s what I explored 🔹 Built a recursive tree structure to handle nested folders & files 🔹 Understood how recursion actually works in real UI problems 🔹 Implemented core features: → Create file / folder → Delete (with full nested structure) → Dynamic rendering 🔹 Learned an important pattern: 🔹filter + map + recursion = tree operations 🔹 Got deeper clarity on handling nested data: → Managing deeply nested state → Updating tree efficiently → Thinking recursively instead of flat logic Biggest takeaway: If you truly understand recursion, you can solve complex UI problems much more cleanly. Building real features inside projects hits very different than just watching tutorials #React #FrontendDevelopment #WebDevelopment #LearningInPublic #JavaScript #BuildInPublic
To view or add a comment, sign in
-
-
👉 If you're writing modern JavaScript, these 10 underrated features can instantly improve your code 👇 💡 Optional Chaining ("?.") → Stop “cannot read property of undefined” errors 💡 Nullish Coalescing ("??") → Smarter defaults (without breaking "0" or """") 💡 Array.at() → Clean way to access last elements 💡 structuredClone() → Proper deep copy (no hacks) 💡 Promise.any() → First successful API wins 💡 Object.hasOwn() → Safer property checks 💡 replaceAll() → Replace all matches without regex 💡 Top-Level Await → Cleaner async code in modules 💡 Logical Assignment ("||=", "&&=", "??=") → Write less, do more 💡 WeakMap / WeakSet → Memory-efficient data handling 🔥 These aren’t “advanced” features — They’re modern JavaScript essentials in 2026. --- 💬 Curious — Which one are you already using in production? And which one is new for you? --- #JavaScript #WebDevelopment #Frontend #FullStackDeveloper #Coding #SoftwareEngineering #TechJobs
To view or add a comment, sign in
-
🧠 JavaScript Array Methods — Complete Cheat Sheet While working with JavaScript daily, I realized one thing… 👉 Strong fundamentals = Faster development + Better code So I created a quick breakdown of the most useful array methods 👇 🔹 Creation Create arrays from different sources → Array.from(), Array.of(), Array.isArray() 🔹 Add / Remove Modify array elements → push(), pop(), shift(), unshift() 🔹 Modify Control structure of arrays → splice() (mutates) → slice() (non-mutating) 🔹 Searching Find values quickly → indexOf(), includes() 🔹 Find ( Important) → find(), findIndex() → findLast(), findLastIndex() 🔹 Transform / Loop → map() → transform data → filter() → select data → reduce() → build single result 🔹 Conditions → some() → at least one true → every() → all true 🔹 Sorting → sort() (mutates) → toSorted() (immutable) 🔹 Flatten / Combine → concat(), flat(), flatMap() 🔹 Modern ( Must Know) → toSpliced(), toReversed(), with() 👉 Immutable operations = cleaner code 🔹 Access → at() (supports negative index 👀) 💡 Key Learning: JavaScript arrays are not just lists — they are powerful tools to write clean, efficient, and scalable code. Understanding when to use: → map vs forEach → filter vs find → mutable vs immutable methods …can completely change your coding style 🚀 📌 Tip: Start using more immutable methods — they help avoid bugs in large applications. Which array method do you use the most? 🤔 #JavaScript #WebDevelopment #FrontendDevelopment #Coding #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 20 – Deep vs Shallow Copy in JavaScript Ever changed a copied object… and accidentally modified the original too? 😅 Yeah, that’s the shallow copy trap. Let’s fix that today 👇 🔹 Shallow Copy Copies only the first level 👉 Nested objects still share the same reference 🔹 Deep Copy Creates a fully independent clone 👉 No shared references, no unexpected bugs 💡 Real-world example (Angular devs 👇) When working with forms, APIs, or state (NgRx), a shallow copy can silently mutate your original data — leading to hard-to-debug UI issues. ⚡ Best Ways to Deep Copy ✔️ structuredClone() (modern & recommended) ✔️ JSON.parse(JSON.stringify(obj)) (with limitations) ✔️ _.cloneDeep() (lodash) 🔥 TL;DR Shallow Copy → Shares references Deep Copy → Fully independent Prefer structuredClone() whenever possible 💬 Have you ever faced a bug because of shallow copying? Drop your experience 👇 #JavaScript #Angular #WebDevelopment #Frontend #Programming #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 30 of My Full Stack Development Journey Today I explored String methods in JavaScript and learned how to manipulate and work with text data effectively ⚡ Here’s what I learned today: 🔹 String Methods – Working with built-in functions 🔹 trim() – Removing extra spaces 🔹 Strings are Immutable – Understanding how strings behave in JS 🔹 toUpperCase() & toLowerCase() – Changing text case 🔹 indexOf() – Finding positions in a string 🔹 Method Chaining – Combining multiple methods 🔹 slice() – Extracting parts of a string 🔹 replace() & repeat() – Modifying and repeating text 🔹 Practiced several questions to strengthen my understanding 💻 It’s interesting to see how powerful JavaScript becomes when working with strings. Step by step, improving my coding skills and logic 🚀 #FullStackJourney #WebDevelopment #JavaScript #LearningInPublic #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
Day 2: The Secret Life of a Function Call — Global vs. Local Execution Context 🚀 Today, I went deeper into the "Big Box" of JavaScript to understand exactly what happens when we call a function. Using this simple square function as an example, here is the line-by-line magic: 🎭 The Two-Phase Performance Phase 1: Memory Allocation Before a single line of code runs, JavaScript scans everything. n, square2, and square4 are allocated memory and set to undefined. The square function gets its own memory space with the entire function code stored inside. Phase 2: Code Execution Line 1: n is assigned the value 2. Line 6: This is where it gets interesting! A Function Invocation happens. 📦 The "Mini Box": Functional Execution Context When square(n) is called, a New Execution Context is created inside the Global one! Memory Phase: A local variable ans is created (undefined). Code Phase: num becomes 2, ans becomes 4. The Return Statement: This is the exit signal. It returns the value 4 to square2 and destroys the local execution context immediately. 📚 The Call Stack: The Manager of it All How does JS keep track of these nested boxes? The Call Stack. It's a stack (LIFO - Last In, First Out). Bottom of stack: Global Execution Context (GEC). When a function is called, it's pushed onto the stack. When it returns, it's popped off. 💡 Interview Tip: Did you know the Call Stack has many names? It’s also called the Execution Context Stack, Program Stack, Control Stack, Runtime Stack, or Machine Stack. Understanding how the stack grows and shrinks is the key to mastering Recursion and avoiding the dreaded "Stack Overflow"! Drop a "🚀" if you’re also following the Namaste JavaScript series! #JavaScript #WebDevelopment #CallStack #ExecutionContext #ProgrammingLogic #FrontendEngineer #CodingCommunity #JSFundamentals
To view or add a comment, sign in
-
-
How JavaScript Memory Model Works: Stack vs Heap Allocation ? (1) Stack stores primitives and references – Fast, LIFO-structured memory for execution contexts, local variables, and primitive values, but limited in size. (2) Heap stores complex data – Larger, slower, unordered memory for objects, arrays, functions, and closures. (3) References connect stack to heap – Variables on the stack hold memory addresses (pointers) that reference data stored in the heap. (4) Primitives live directly on the stack – Values like numbers and strings (when small) are stored inline, while strings and complex types use heap references. (5) Functions are heap-stored with scope – Function bodies reside in the heap, while references and scope chains remain on the stack during execution. Test your JavaScript fundamentals with focused on scope, hoisting, closures, and asynchronous behavior. 💬 Share your answer or reasoning in the comments. #JavaScript #InterviewPreparation #SoftwareEngineering #WebDevelopment #DevelopersOfLinkedIn #frontend #backend #coding #learning
To view or add a comment, sign in
-
-
📘 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐌𝐨𝐝𝐮𝐥𝐞 (𝐁𝐚𝐬𝐢𝐜) 𝐒𝐞𝐜𝐭𝐢𝐨𝐧 6: 𝐀𝐫𝐫𝐚𝐲 & 𝐋𝐨𝐨𝐩𝐬 🔹 𝐀𝐫𝐫𝐚𝐲 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 1.What is array / collection / list? Why use it? 2.Array syntax / How to declare an array? 3.What is array index? 4.Array index starts from? 5.How to access element? 6.How to set value? 7.Findout Array length / How to find total length? 8.Array methods? 9.What is array method? 10.Why use array method? 🔹 𝐋𝐨𝐨𝐩 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 1.What is loop? 2.Why use loop? 3.Loop structure? 4.Types of loop? 5.Array loop / Array specific loops? 6.Array is immutable or mutabl? 7.What is loop iteration? 8.Loop control statements? 9.What is array of object? 10.Why use array of object? 🎯 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 (𝐄𝐱𝐭𝐫𝐚) 1.What is the main difference between slice() and splice()? 1.What is the difference between map() and forEach()? (Which one should you use when?) 2.What is the difference between filter() and find()? (Which one should you use when?) 3.When to use reduce()? 4.Difference between for...in() and for...of()? #DotNet #AspNetCore #MVC #FullStack #SoftwareEngineering #ProgrammingTips #DeveloperLife #LearnToCode #JavaScript #JS #JavaScriptTips #JSLearning #FrontendDevelopment #WebDevelopment #CodingTips #CodeManagement #DevTools
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
Appreciate the mention! Your support means a lot to us! 🙏