'5'+1 = '51' & '4'-1 = 3 How is possible in JS!. 🧠 Mastering JavaScript — One Concept at a Time (3/32) I realized something simple but powerful. 📦 What Are Data Types? A data type defines what kind of data is being stored a number, text, boolean, object, and so on. In JavaScript, data types are divided into two main categories: 🔹 1. Primitive Types These are copied by value (they create a separate copy). String, Number, Boolean, Undefined, Null, Symbol, BigInt. Primitives are simple and predictable — changing one doesn’t affect another. 🔹 2. Reference Types (Non-Primitive) These are copied by reference, not by value. Object, Array, Function. Instead of copying the actual data, JavaScript copies the memory reference. That’s why modifying one object can sometimes affect another variable pointing to the same object — and that’s where many beginners get confused. 🔍 The typeof Operator JavaScript gives us a tool to check types — typeof. Most results are straightforward: string → "string" number → "number" boolean → "boolean" undefined → "undefined" But then there’s one famous quirk: 👉 typeof null returns "object" This is actually a long-standing JavaScript bug — and it still exists today. Understanding this prevents a lot of confusion during debugging. 🔁 Type Coercion (The Sneaky Part) JavaScript sometimes automatically converts types during operations. For example: When a string and number are added together, JavaScript may perform concatenation instead of addition. Subtraction forces numeric conversion. Booleans, null, and undefined can also behave unexpectedly in arithmetic operations. This automatic behavior is called type coercion — and it’s one of the most misunderstood parts of JavaScript. Instead of memorizing outputs, I’m now trying to understand: How values are stored How they are copied How JavaScript decides to convert them That clarity changes everything. What was the most confusing type behavior you faced when learning JavaScript? #JavaScript #LearningInPublic #WebDevelopment #FrontendDevelopment #MasteringJavaScript

To view or add a comment, sign in

Explore content categories