𝗛𝗮𝘃𝗲 𝘆𝗼𝘂 𝗲𝘃𝗲𝗿 𝘀𝘁𝗼𝗽𝗽𝗲𝗱 𝗮𝗻𝗱 𝗮𝘀𝗸 𝘆𝗼𝘂𝗿𝘀𝗲𝗹𝗳 𝘄𝗵𝘆 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗶𝘀 𝗽𝗮𝘀𝘀 𝗯𝘆 𝘃𝗮𝗹𝘂𝗲, 𝗮𝗻𝗱 𝗻𝗼𝘁 𝗽𝗮𝘀𝘀 𝗯𝘆 𝗥𝗲𝗳𝗲𝗿𝗲𝗻𝗰𝗲?🤔 You see... when a value is passed into a function in JS, the function receives a copy of that value, not ❌direct access to the original variable. This means a function cannot reassign the caller’s variable or take ownership of it. For primitive values like (numbers, strings, booleans...), the copied value is independent, so changes inside the function do not affect the original value. (e.g reassigning) For objects and arrays(non-primitives), the copied value happens to be a reference (memory address) to the same object. So, mutating the object inside the function affects the original object but reassigning the reference does not! 🚫 so... JavaScript always passes values, but for objects, the value being passed is a reference ✅✅. If you understand this, it will surely save you from debugging headaches 🧑💻🧑💻 . . . . . #JavaScript #CodingTips #WebDevelopment #Programming #LearnToCode #CodeNewbie #SoftwareEngineering #DevTips #TechCommunity
JavaScript Value Passing: Primitive vs Object Behavior
More Relevant Posts
-
🧠 Shallow Copy vs Deep Copy in JavaScript When working with objects in JavaScript, copying data the wrong way can create unexpected bugs. Shallow Copy copies the reference of nested objects. So changes in one object can affect the other. Deep Copy creates a completely independent copy, including nested objects. ✔ Shallow Copy → Faster but shares references ✔ Deep Copy → Safer for nested data Understanding this small concept can help avoid many hidden bugs in applications. #JavaScript #WebDevelopment #CodingTips #Programming #ReactJS
To view or add a comment, sign in
-
-
✍️ One syntax change. Massive readability improvement. I wrote a complete guide on Template Literals in JavaScript — and why every developer should stop using + for string building. What's covered: → The exact problems with traditional string concatenation → How backtick strings work and what ${} actually does → Embedding variables, expressions, ternaries, and function calls inline → Multi-line strings — write HTML, SQL, and logs the way they're meant to look → Real use cases: dynamic URLs, HTML generation, dynamic class names, logging → Tagged template literals — how styled-components and GraphQL's gql work under the hood Readability is not a nice-to-have. It's how you write code other people (and future you) can actually maintain. Read the full blog here 👇 🔗https://lnkd.in/gJJp2xut Check out my Hashnode profile 👇 🔗 https://lnkd.in/gAwxuryw #JavaScript #WebDevelopment #CleanCode #Programming #ES6 #piyushgarg #chaicode #hiteshchoudhary
To view or add a comment, sign in
-
-
I thought JavaScript arrays worked like C arrays… I was wrong. ❌ I believed: 👉 Arrays are stored in contiguous memory 👉 Indexing is just base + offset 👉 Everything sits neatly in one block But JavaScript doesn’t work like that. Here’s the real mental model 👇 ✅ The variable (arr) lives in the STACK ✅ It stores a reference (not the actual array) ✅ The actual array lives in the HEAP ✅ The array stores: • metadata (like length) • pointer to elements storage Now the interesting part: 👉 Elements can be: * primitives (numbers, booleans) * references (strings, objects) 👉 Strings/objects are usually stored separately in memory 👉 Arrays can be dynamic, sparse, and optimized internally ⚠️ Most important: JavaScript arrays are NOT guaranteed to be contiguous in memory. That means: They are closer to dynamic objects than low-level arrays. 💡 Actual storage depends on the JS engine (like V8), which heavily optimizes things under the hood. I made a diagram to simplify this 👇 Course Instructor: Rohit Negi | Youtube Channel: Coder Army #JavaScript #webdevelopment #buildinpublic #learninginpublic #fullstackdevelopment.
To view or add a comment, sign in
-
-
Continuing my journey into JavaScript, I’ve just published a new blog post! This time, I’m breaking down JavaScript Operators—the fundamental building blocks that allow us to manipulate data and build logic in our code. In this guide, I cover: ✅ Arithmetic Operators (+, -, *, /, %) – The math behind the logic. ✅ Comparison Operators (==, ===, !=, >, <) – Understanding how to evaluate conditions . ✅ Strict Equality (===) – Why type checking matters! ✅ Logical & Assignment Operators (&&, ||, !, =, +=) – Flow control and data handling. I’ve included plenty of practical examples to make these concepts stick for good. A big shoutout once again to Hitesh Choudhary sir for the incredible guidance in making these basics so clear and easy to understand. Check out the full guide here: https://lnkd.in/e7s4tANn Akash Kadlag | Jay Kadlag | #JavaScript #CodingBasics #WebDevelopment #Programming #Hashnode #TechCommunity #LearnToCode #chaiaurcode
To view or add a comment, sign in
-
-
🛡️ Advanced JavaScript — Day 2: Form Validation with Regex Today I built a Form Validation project using JavaScript — and this one was different from anything I'd done before. Not because forms are complex. But because today I used Regex for the first time to validate inputs — and it completely changed how I think about data validation. Here's everything I covered and built today 👇 📌 What is Form Validation? 📌 preventDefault() 📌 Regex — Regular Expressions 🔍 📌 Dynamic Error Messages 📌 isValid Flag Simple pattern. Used everywhere in production code. Form validation isn't just about blocking bad data. It's about respecting the user — giving clear, instant feedback instead of letting them wonder what went wrong. Project done. Concepts understood. Moving forward.... #AdvancedJavaScript #JavaScript #FormValidation #Regex #100DaysOfCode #LearnInPublic #WebDevelopment #Frontend #Programming #CodingJourney #BuildInPublic
To view or add a comment, sign in
-
-
Building on the basics of JavaScript, I’ve gained a solid understanding of how core components build a functional system. Writing code is the heart of this process, and seeing these concepts integrate is a major highlight of my learning. I have been practicing variable assignments using let, const, and var, while using typeof to identify different data types. I also learnt how to structure Control Flow through if/else statements, switch cases, and comparison operators. By using logical operators—specifically AND (&&) and OR (||)—along with strict equality (===), I can now set multiple rules for my code. I understand how to ensure that if a primary condition isn't met, the "else" logic applies correctly so the program follows a specific path. I also learnt how to use for loops combined with the .length property. This allows the code to automatically track the number of characters or items in a dataset. Instead of hard-coding values, I can now write dynamic code that adjusts to the data it receives. I am still working through the fundamentals, and I am excited to see how everything will work together once the foundation is complete! #JavaScript #WebDevelopment #CodingJourney #SoftwareEngineering #Techcrush #Frontend
To view or add a comment, sign in
-
-
🚀 𝐓𝐲𝐩𝐞𝐒𝐜𝐫𝐢𝐩𝐭 𝐒𝐞𝐫𝐢𝐞𝐬 — 𝐀𝐫𝐭𝐢𝐜𝐥𝐞 𝟎𝟐 𝙇𝙖𝙗𝙚𝙡𝙚𝙙 𝘽𝙤𝙭𝙚𝙨: 𝙐𝙣𝙙𝙚𝙧𝙨𝙩𝙖𝙣𝙙𝙞𝙣𝙜 𝙑𝙖𝙧𝙞𝙖𝙗𝙡𝙚𝙨 𝙖𝙣𝙙 𝘽𝙖𝙨𝙞𝙘 𝙏𝙮𝙥𝙚𝙨 𝙞𝙣 𝙏𝙮𝙥𝙚𝙎𝙘𝙧𝙞𝙥𝙩 𝐕𝐚𝐫𝐢𝐚𝐛𝐥𝐞𝐬 in programming are like boxes that store data. In real life, we use labels to easily identify what’s inside a box, right? Because if a box has a label, it’s easy to understand what’s inside. If it doesn’t, things get confusing. The same concept applies to programming. But in 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭, these boxes don’t have labels. So inside a single JavaScript variable, you can store: 👉 a 𝙣𝙪𝙢𝙗𝙚𝙧 👉 a 𝙨𝙩𝙧𝙞𝙣𝙜 👉 a 𝙗𝙤𝙤𝙡𝙚𝙖𝙣 This flexibility might seem useful… But it’s one of the main reasons behind 𝐫𝐮𝐧𝐭𝐢𝐦𝐞 𝐞𝐫𝐫𝐨𝐫𝐬. 💡 𝐓𝐲𝐩𝐞𝐒𝐜𝐫𝐢𝐩𝐭 solves this problem using 𝙩𝙮𝙥𝙚𝙨. It allows you to add labels to your variables: 👉 If you only need to store 𝙩𝙚𝙭𝙩 inside a variable, you can use the 𝙨𝙩𝙧𝙞𝙣𝙜 type. 👉 If you only need to store 𝙣𝙪𝙢𝙗𝙚𝙧𝙨 inside a variable, you can use the 𝙣𝙪𝙢𝙗𝙚𝙧 type. 👉 If you only need to store 𝙩𝙧𝙪𝙚/𝙛𝙖𝙡𝙨𝙚 inside a variable, you can use the 𝙗𝙤𝙤𝙡𝙚𝙖𝙣 type. By using these types: ✅ Your code becomes safer ✅ Bugs are reduced ✅ Developer experience improves In this article, I explain: 📦 What variables really are 🏷️ How type labels work in TypeScript 🧠 What Type Inference is ⚙️ The role of the TypeScript compiler 📖 Read the full article here: 👉 https://lnkd.in/g725SZP4 #TypeScript #JavaScript #WebDevelopment #Programming #LearningInPublic #SoftwareEngineering🚀
To view or add a comment, sign in
-
-
The Ultimate JavaScript Array Methods Cheat Sheet for Developers JavaScript array methods are powerful tools for manipulating and transforming data efficiently. This comprehensive cheat sheet provides detailed explanations, syntax, and practical examples for all essential array methods, helping you write cleaner, more efficient, and modern JavaScript code. Read the full article 👇 https://lnkd.in/d_q_Ynf9 #Programming #WebDevelopment #SoftwareEngineering #Tech #Coding #JavaScript #JSArrayMethods #FrontendDevelopment #JavaScriptTips #ArrayMethods #FutureOfWork #DigitalTransformation
To view or add a comment, sign in
-
-
A small JavaScript concept that can cause real production bugs: Pass by Reference In JavaScript, objects are passed by reference, not copied. This means when you pass an object to a function, the function can modify the original object in memory. In a real system like a payment pipeline, this can cause serious problems. If multiple services use the same object, one mutation can accidentally change data for others leading to wrong charges, incorrect logs, or duplicated discounts. Now the original data remains untouched, making the system predictable and easier to debug. This is one reason why architectures using Redux, functional programming, and event-driven systems prefer immutability. Sometimes the smallest language features shape the reliability of large systems.
To view or add a comment, sign in
-
Today I practiced the "Middle of the Linked List" problem while working on Data Structures in JavaScript. The challenge was to return the middle node of a singly linked list. If the list has two middle nodes, the second one should be returned. Instead of counting the length of the list first, I implemented the Fast and Slow Pointer technique: Slow pointer moves one step at a time Fast pointer moves two steps at a time When the fast pointer reaches the end, the slow pointer naturally lands at the middle of the list. This approach solves the problem in O(n) time and O(1) space, which is much more efficient than calculating the list length separately. Working through these problems is helping me strengthen my understanding of pointers, traversal patterns, and algorithmic thinking in JavaScript. #javascript #dsa #datastructures #algorithms #leetcode #programming #softwareengineering
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