Primitive vs Non-Primitive Data Type in JavaScript I remember when I was learning Javascript, I often got confused between primitive and non-primitive (or reference) types. But as soon as I could visualize how it works in memory — everything fell into place! 💡 Here’s the key idea 👇 🧱 Primitive (as in string, number, boolean, null, undefined, symbol etc) → store plain values into the memory (stack). 🧩 Non-Primitive types (object, array, function) → store addresses (references) to values in memory (heap). So when we copy a primitive value, it becomes a new one. Non-primitive types are different: when we copy them, the two variables still point to the same object! 😯 So knowing this small detail really HELPS a LOT in debugging and Understanding JavaScript behavior better. 💬 Have you ever been surprised by how objects or arrays behave in JS? #JavaScript #WebDevelopment #CodingJourney #FrontendDevelopment #LearnToCode #Programming #DeveloperCommunity #CodingBasics
Understanding Primitive vs Non-Primitive Data Types in JavaScript
More Relevant Posts
-
🫢 Ever wondered what happens behind the scenes when you reassign a value in JavaScript? 🤔 👉 When you update a primitive data type (like string, number, boolean, undefined, null, symbol, or bigint), you’re not actually changing the existing value. 👉 Instead, JavaScript silently creates a new value in memory and points your variable to it. 🎯 👉 It’s like getting a brand-new notebook instead of erasing the old one — the old still exists, but you’ve just started fresh. 📒 ✨ So, while it looks like you’re modifying the value, you’re actually reassigning a new memory reference every time. 🌠 As they say, “Appearances can be deceiving.” 😉 The value seems to change, but deep down, it never truly does! 💡 In short: We often know that strings are immutable, but here’s the twist — all primitive data types are immutable in JavaScript! 🔥 💬 Idiom: “Appearances can be deceiving.” — Things may not be as they seem; something that looks one way on the surface may actually be very different underneath. #JavaScript #CodingTips #Programming #TechInsights #LearnToCode #DeveloperLife #FrontendDevelopment #CodeWisdom #ProfessionalLearning #CareerGrowth #JS #WebDevelopment
To view or add a comment, sign in
-
-
🧮 Finding the Median in JavaScript – Quick Tip! While working with numerical data, calculating the median is a common task. Here’s a clean and efficient way to find the median of an array in JavaScript 🧠 How it works: Sort the array in ascending order. Find the middle index. If the length is odd, return the middle element. If the length is even, return the average of the two middle elements. 💡 Output: For [1, 3, 2, 5, 4], the sorted array is [1, 2, 3, 4, 5] → Median = 3 ✅ A simple yet powerful example of handling statistics in JavaScript. #JavaScript #Coding #WebDevelopment #Learning #CodeSnippet #ProgrammingTips
To view or add a comment, sign in
-
-
🚀 JavaScript Revision Series — Day 2 Today I revised one of the most important concepts in JavaScript: Primitive vs Reference Data Types — the reason why kabhi kabhi code “unexpected” behave karta hai 😅 🟡 Primitive Data Types (String, Number, Boolean, Null, Undefined, Symbol, BigInt) 📌 They always pass copies, so original value safe. 🔵 Reference Data Types (Arrays, Objects, Functions) 📌 They pass reference, so ek me change = dono me change. Example: arr2 = arr1; arr2.pop(); 👉 Dono arrays change 😭 --- 😄 Little JavaScript Moment Real life: 5 + 1 = 6 JavaScript: "5" + 1 = "51" Why? Because JS said: > “+? Oh, you want string mode!” 😂 But "5" - 1 = 4, kyun? > “Subtraction? Number mode on!” --- 🔍 Extra Concepts Covered ✔ typeof ✔ == vs === ✔ Type conversion basics --- 🔗 Daily Practice Repo: https://lnkd.in/ejQk84Zg Learning step by step, and enjoying the process! 💻✨ #JavaScript #JavaScriptBasics #LearningJourney #WebDevelopment #FrontendDevelopment #CodingJourney #MERNStack #MernStackLearner #ConsistencyIsKey #Saylani #SMIT #DeveloperCommunity
To view or add a comment, sign in
-
-
💡 Mastering JavaScript Data Types: Your Essential Guide! 💡 Understanding data types is foundational to writing clean, efficient, and bug-free JavaScript code. Whether you're a beginner or looking for a quick refresh, this visual breakdown is a fantastic resource! This infographic clearly illustrates the distinction between Primitive and Non-primitive (composite) data types, covering everything from Number and String to Objects, Arrays, and Maps. 🚀 What's your go-to data type in JS and why? Share your insights below! #JavaScript #WebDevelopment #Programming #Coding #Developer #Tech #DataTypes #JS
To view or add a comment, sign in
-
-
🚀 Master JavaScript Arrays — From Basics to Advanced! Arrays are the backbone of data manipulation in JavaScript — from handling lists of items to building complex data structures. 📊 This guide covers everything you need to know — ✅ Creating, accessing, and modifying arrays ✅ Copying & cloning techniques (mutable vs. immutable) ✅ Modern methods like toReversed(), toSorted(), toSpliced(), and with() ✅ Deep dive into static & iterator methods (map, filter, reduce, find, flatMap, and more) ✅ Practical exercises and real-world challenges Whether you’re a beginner brushing up your fundamentals or an intermediate dev polishing your skills, this post is packed with examples and clear explanations to make Arrays second nature. 💪 📄 Download the full PDF below and start mastering one of the most powerful parts of JavaScript today. #JavaScript #FrontendDevelopment #WebDevelopment #Coding #Learning #Arrays #JSDeveloper
To view or add a comment, sign in
-
🚀 Master JavaScript Arrays — From Basics to Advanced! Arrays are the backbone of data manipulation in JavaScript — from handling lists of items to building complex data structures. 📊 This guide covers everything you need to know — ✅ Creating, accessing, and modifying arrays ✅ Copying & cloning techniques (mutable vs. immutable) ✅ Modern methods like toReversed(), toSorted(), toSpliced(), and with() ✅ Deep dive into static & iterator methods (map, filter, reduce, find, flatMap, and more) ✅ Practical exercises and real-world challenges Whether you’re a beginner brushing up your fundamentals or an intermediate dev polishing your skills, this post is packed with examples and clear explanations to make Arrays second nature. 💪 📄 Download the full PDF below and start mastering one of the most powerful parts of JavaScript today. #JavaScript #FrontendDevelopment #WebDevelopment #Coding #Learning #Arrays #JSDeveloper
To view or add a comment, sign in
-
JavaScript Deep Dive: The Story Behind null Today, I explored the origins of one of JavaScript’s quirkiest features — null. It turns out this little value has a surprising history! 🔹 Where it Began: JavaScript was created in 1995 by Brendan Eich in just 10 days. Since it was inspired by Java, null was included to represent the intentional absence of any object — just like in Java. 🔹 The Famous Bug: Ever wondered why this happens? typeof null // "object" This result is actually due to an early implementation bug. null was given the same type tag as objects — and fixing it would have broken lots of existing code. So it stayed. 😅 🔹 null vs undefined: JavaScript defines two empty values: null: Intentionally empty (set by programmers) undefined: Automatically assigned by JavaScript for missing or uninitialized values This distinction has confused developers for decades! 🔹 Standardized in ECMAScript: Both null and undefined were formalized in the first ECMAScript standard (1997), cementing their roles in the language. 💡 Takeaway: JavaScript's null is a great example of how early design decisions — even mistakes — can shape a language's future. Knowing its history helps us write code with more clarity and intention. Let’s keep learning the story behind the code! 🎯 #JavaScript #LearningInPublic #WebDevelopment #HistoryOfJS #Programming #10000Coders #CodeNewbie
To view or add a comment, sign in
-
-
🛑 Still using this to deep clone objects in JavaScript? JSON.parse(JSON.stringify(obj)) It works… until it doesn’t 😅 It breaks with: ❌ Dates (turn into strings) ❌ Maps / Sets (lost completely) ❌ undefined & functions (removed) ❌ Circular references (throws error) JavaScript now has a modern, safer solution: structuredClone(obj) ✨ Supports circular references ✨ Preserves Date, Map, Set, RegExp ✨ Faster & built-in in modern JS/Node I wrote a simple blog with easy examples explaining why this matters, including a quick view of Shallow vs Deep cloning so the concept is crystal clear even for beginners. 🔗 Read it here: https://lnkd.in/dVcGiNwv #JavaScript #WebDevelopment #Programming #NodeJS #TypeScript #JSTips #CleanCode #SoftwareEngineering #Developers #WebDev #CodingLife
To view or add a comment, sign in
-
-
From Function Constructors to Classes — How We Create Objects in Modern JavaScript Back in the day, people used function constructors and the new keyword to create objects. But JavaScript evolved — and now we use the class syntax introduced in ES6 (2015). Here’s how both look side by side Old Way — Function Constructor function Person(first, last) { this.firstname = first; this.lastname = last; } Person.prototype.getFullName = function() { return `${this.firstname} ${this.lastname}`; }; const john = new Person("John", "Doe"); console.log(john.getFullName()); // John Doe Modern Way — ES6 Class class Person { constructor(first, last) { this.firstname = first; this.lastname = last; } getFullName() { return `${this.firstname} ${this.lastname}`; } } const john = new Person("John", "Doe"); console.log(john.getFullName()); // John Doe Cleaner syntax Easier inheritance using extends Same behavior under the hood — still uses prototypes! The Truth Even though class looks like something from Java or Python... It’s just syntactic sugar over the same old prototype system. The new keyword still: 1️⃣ Creates an empty object 2️⃣ Sets this to that object 3️⃣ Runs the constructor() 4️⃣ Returns the new object Pro Tip Don’t stop at syntax — understand what’s happening underneath. When you truly get how class, new, and prototypes interact, you start writing JavaScript that’s not just functional — but elegant. #JavaScript #ES6 #FrontendDevelopment #WebDevelopment #LearnToCode #JSClasses #CodingTips #WebDevCommunity #PrototypalInheritance #ProgrammingForBeginners
To view or add a comment, sign in
-
🚀 Day 7 of My 30 Days of JavaScript Journey ✅ Challenge: Array Reduce Transformation (LeetCode #2626) Write a function reduce(nums, fn, init) that processes each element of the array using the given reducer function fn, starting from an initial value init. This function should accumulate results sequentially and return the final value — implemented without using the built-in Array.reduce() method. 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/gxsp26cz 💡 Solution: https://lnkd.in/giZj_hYw 🧠 Concept Highlighted: This problem deepened my understanding of accumulator functions, data aggregation, and sequential computation in JavaScript. It helped me explore how the powerful reduce() method works behind the scenes — a key tool for transforming and summarizing data efficiently. #Day7 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #LearningEveryday #ProblemSolving #FunctionalProgramming
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