Assalam o Alaikum everyone, JavaScript Lesson 29 is here: Reference vs Value, Shallow Copy, Deep Copy & Immutable Patterns. This lesson covers one of the most important JavaScript concepts for writing clean and predictable code: understanding how values are stored, copied, and updated in memory. I explained the difference between primitive values and reference values, then demonstrated what happens when you assign objects and arrays directly. From there, I showed how to create shallow copies using spread syntax and Object.assign(), and why shallow copy can still cause problems with nested objects. I also covered deep copy using both: - JSON.parse(JSON.stringify()) - structuredClone() After that, I moved into immutable programming patterns, where I showed how to update arrays and objects without mutating the original data using: - filter() - map() - spread syntax - destructuring This is a very practical topic for JavaScript developers because immutability helps prevent bugs and makes code easier to maintain in real projects. Watch the lesson: https://lnkd.in/dSeTxYPP #JavaScript #ReferenceVsValue #ShallowCopy #DeepCopy #ImmutablePatterns #JavaScriptTutorial #WebDevelopment #FrontendDevelopment #Programming #CodingTutorial #DeveloperMaroof #LearnJavaScript #JavaScriptBasics #ModernJavaScript #SpreadOperator #ObjectAssign #StructuredClone #Immutability #JSConcepts #JavaScriptLessons
JavaScript Lesson 29: Reference vs Value, Shallow Copy & Immutable Patterns
More Relevant Posts
-
Assalam o Alaikum everyone, JavaScript Lesson 30 is here: Pure Functions, Higher-Order Functions, Function Composition & Currying. This lesson focuses on functional programming concepts that help you write cleaner, more reusable, and more predictable JavaScript code. I started with pure functions and explained why they are important: same input, same output, and no side effects. Then I showed the difference between pure and impure functions using real examples like add() and an increment() function that changes external state. After that, I covered higher-order functions, where functions can accept other functions as arguments or return a function as output. I also demonstrated how to create reusable behavior with a function that returns another function, like createGreeter(). Next, I explained function composition using pipe(), which lets you chain transformations together in a clean left-to-right flow. Finally, I covered currying and partial application, showing how one function can be broken into smaller reusable steps. In this lesson, you will learn: • pure vs impure functions • side effects in JavaScript • higher-order functions • returning functions from functions • function composition with pipe() • currying and partial application • arrow function currying This is a very useful lesson for anyone who wants to understand functional programming patterns in JavaScript and write better code in real projects. Watch the lesson: https://lnkd.in/dVyfGvcP #JavaScript #PureFunctions #HigherOrderFunctions #Currying #FunctionComposition #FunctionalProgramming #JavaScriptTutorial #WebDevelopment #FrontendDevelopment #Programming #DeveloperMaroof #LearnJavaScript #JavaScriptConcepts #CleanCode #JavaScriptLessons
To view or add a comment, sign in
-
-
🚀 Day 4 of my JavaScript Coding Practice Today’s problem: Two Sum var twoSum = function(nums, target) { const map = new Map(); // Store: { value : index } for (let i = 0; i < nums.length; i++) { const complement = target - nums[i]; // If the needed number is already in our map, we found the pair! if (map.has(complement)) { return [map.get(complement), i]; } // Otherwise, save the current number and its index map.set(nums[i], i); } return []; // Return empty if no pair is found }; 💡 Instead of using brute force (O(n²)), I used a HashMap approach to solve it in O(n) time. Key takeaway: Understanding how to trade space for time can significantly optimize performance. Small steps every day → Big improvements over time 📈 #JavaScript #DSA #CodingPractice #100DaysOfCode #FrontendDevelopment
To view or add a comment, sign in
-
-
One small word in JavaScript causes a lot of confusion: undefined. Many developers encounter it but don’t fully understand why it appears. In my latest article, I break it down in a practical way: • What undefined actually means • Common scenarios where it shows up • Mistakes developers often make • How to avoid it in real projects This is especially useful if you're learning JavaScript or improving your debugging skills. 🔗 Read the full article: https://lnkd.in/gaGDuAHp Curious — what was the most confusing JavaScript concept for you when you started? #JavaScript #WebDevelopment #FrontendDevelopment #Programming #Coding #SoftwareDevelopment #Debugging #LearnJavaScript
To view or add a comment, sign in
-
Day 6 / 30 - JavaScript Coding Practice Today’s problem: Roman to Integer var romanToInt = function (s) { if (s.length > 15) { return; } const romanMap = new Map([ ['I', 1], ['V', 5], ['X', 10], ['L', 50], ['C', 100], ['D', 500], ['M', 1000] ]); let sum = 0; let preValue = 0; for (let k = s.length - 1; k >= 0; k--) { let currentVal = romanMap.get(s[k]); if (currentVal < preValue) { sum -= currentVal; } else { sum += currentVal; } preValue = currentVal; } return sum; }; 💡 Key Insight: Instead of scanning from left to right, I iterated from right to left to easily handle subtraction cases like IV (4) and IX (9). 👉 If a smaller value comes before a larger one → subtract 👉 Otherwise → add #JavaScript #DSA #CodingPractice #ProblemSolving #100DaysOfCode #FrontendDevelopment
To view or add a comment, sign in
-
-
🚀 Garbage Collection in JavaScript Ever wondered what happens to unused memory? 🤔 Let’s make it simple 👇 🧠 What is Garbage Collection? 👉 It is the process of automatically removing unused memory 👉 JavaScript handles this for you (no manual memory management) ⚡ How does JS decide what to remove? 👉 Using Reachability ✔ Reachable = Still in use ❌ Unreachable = Garbage 💡 Simple Example: 👉 If no variable is referencing an object 👉 It becomes eligible for garbage collection 🔥 Algorithm Used: 👉 Mark & Sweep ✔ Mark → Identify reachable objects ✔ Sweep → Remove unreachable objects ⚡ Key Understanding: 👉 If no reference points to an object 👉 It gets removed from memory 🚨 Important Note: 👉 Garbage collection is automatic 👉 You cannot control when it runs 💬 Did this concept clear your doubt? 📌 Save this for interviews (very important topic) #javascript #webdevelopment #frontend #coding #programming #javascriptdeveloper #learncoding #developers #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 JavaScript Practice – Core Logic Building Worked on some important problems without using built-in methods: 🔹 String → Number (without parseInt) using ASCII 🔹 Number → String (manual + template + coercion) 🔹 Count character occurrences ("hello world" → "l" = 3) 🔹 Check if string contains only digits (Regex + ASCII) 💡 Key Learnings: 🔹digit = digit * 10 + (ascii - 48) 🔹Inside range → &&, Outside range → || 🔹digit + str helps maintain correct order 🔥 Strengthening fundamentals and improving problem-solving step by step. #JavaScript #Coding #ProblemSolving #FrontendDevelopment #Learning
To view or add a comment, sign in
-
🔥 I used to think I knew JavaScript… until I discovered this. Early in my career, I was constantly fighting weird bugs: Variables leaking everywhere Random overrides Code breaking for “no reason” Then I stumbled upon this pattern: (function () { console.log('This runs immediately'); })(); It’s called an IIFE (Immediately Invoked Function Expression). This one concept completely changed how I understood scope in JavaScript. Before let and const existed, IIFEs were the go-to solution because they allowed us to: ✅ Execute code immediately ✅ Create private scopes ✅ Prevent polluting the global namespace ✅ Avoid naming collisions It felt like having a private sandbox in your code. But here’s the interesting part 👇 Today, we rarely need IIFEs anymore. Modern JavaScript gives us much cleaner tools: Block scoping with let and const True modules with import / export Arrow functions + better patterns So why should you still care about IIFEs in 2026? Because understanding why they existed helps you truly understand how JavaScript evolved — and why it behaves the way it does. The best developers don’t just learn syntax. They learn the history and the problems each feature was solving. 🧠 My takeaway: Don’t just learn what to use today. Learn why it existed in the first place. That’s what separates good developers from great ones. Have you ever used IIFEs in old codebases? Or did you start learning JavaScript after modules became the standard? Drop a comment 👇 I’d love to hear your experience. #JavaScript #WebDevelopment #Frontend #Programming #CleanCode #Coding
To view or add a comment, sign in
-
-
🚀 Functions Deep Dive Today I didn’t just “learn functions”… I understood how JavaScript actually thinks. Here’s what I explored 👇 🔹 What is a Function A reusable block of code that makes programs cleaner and smarter. 🔹 Function Parameters & Arguments Turning static code into dynamic logic. 🔹 Arrow Functions (ES6) Cleaner syntax, less code, more power. 🔹 Default Parameters Handling missing inputs like a pro. 🔹 First-Class Functions 🔥 This changed everything for me: Functions in JavaScript are treated like values. ✔️ Stored in variables ✔️ Passed as arguments ✔️ Returned from other functions This is the foundation of: ➡️ Callbacks ➡️ Async JavaScript ➡️ React 💡 Biggest Realization: JavaScript isn’t just a language… It’s a system where functions are the core building blocks. 🧠 What I’m focusing on: • Strong fundamentals over shortcuts • Understanding > memorizing • Writing code daily 📌 Next Step: Higher-Order Functions + Real-world practice #javascript #webdevelopment #codingjourney #180daysofcode #frontenddevelopment #reactjs #programming #developers #learninpublic #softwareengineering #matadeenyadav #MatadeenYadav
To view or add a comment, sign in
-
-
Understanding the Event Loop in JavaScript is a turning point for every developer. Many developers use async features like promises, setTimeout, or async/await daily — but very few truly understand what happens behind the scenes. I’ve written a detailed yet easy-to-understand article that breaks down: ✔ Call Stack ✔ Callback Queue ✔ Microtask Queue ✔ Execution Order If you want to strengthen your JavaScript fundamentals and avoid common async mistakes, this will definitely help. 👉 Read the full article: https://lnkd.in/gDhwvmUc I’d love to hear your thoughts — what was the hardest concept for you when learning the Event Loop? #JavaScript #SoftwareDevelopment #WebDevelopment #FrontendDevelopment #AsyncProgramming #Coding #TechLearning
To view or add a comment, sign in
-
🚀 Just Published: Map and Set in JavaScript https://lnkd.in/g-nAm7SZ Understanding Map and Set helps you write more efficient and cleaner JavaScript code. In this article, I covered: ✅ What Map is and how it stores key-value pairs ✅ What Set is and how it ensures unique values ✅ Difference between Map and Object ✅ Difference between Set and Array ✅ When to use Map and Set in real-world scenarios 💡 Learn how Map solves limitations of traditional objects and how Set automatically removes duplicates. If you're preparing for interviews or improving your JS fundamentals, this is a must-read! 🙏 Thanks to amazing mentors and community 🙌 Hitesh Choudhary Sir, Piyush Garg Sir, Akash Kadlag Sir, Suraj Kumar Jha Sir, Chai Aur Code #JavaScript #WebDevelopment #Coding #Frontend #FullStack #Programming #Developers #TechCommunity
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
Love it