Data Types — *7 Fundamentals*
Data Types — *7 Fundamentals*
🎯 After reading this lesson
After finishing this lesson, you will be able to confidently handle the following 3 things.
- ▸✅ The 7 primitives (string·number·bigint·boolean·null·undefined·symbol)
- ▸✅ Reference types and the difference between == vs ===
- ▸✅ The IEEE 754 trap in Number (0.1 + 0.2 ≠ 0.3)
Keep the learning objectives as a checklist, and close the lesson once you can answer all of them.
Data Types in JS
The Core in One Line
JavaScript data types are divided into 7 Primitive types and 1 Object type. Because it is dynamically typed, no type declaration is needed when defining a variable — types are inferred from the value.
The 7 Primitives
Object — Everything Else
Arrays, functions, dates, and regular expressions are all objects internally. That is why method calls are possible (arr.map(), s.toUpperCase(), etc.).
undefined vs null
Two that are commonly confused:
- ▸undefined — assigned automatically (when only declared, or when a function argument is missing)
- ▸null — assigned intentionally by the developer (to signal the absence of a value)
Type Checking
typeof null === 'object' is a famous JS bug. It cannot be fixed due to backwards compatibility. Null checks must be handled separately.
Type Coercion — Implicit vs Explicit
Implicit coercion produces unexpected results. Always prefer explicit coercion.
Summary
- ▸7 primitives (number·bigint·string·boolean·undefined·null·symbol)
- ▸1 object type (includes arrays, functions, dates, etc.)
- ▸typeof null === 'object' is a bug (memorize this)
- ▸Coercion: implicit — no; explicit — yes
⚡ Try It Yourself — typeof · Array.isArray
🤖 Try Asking AI Like This
Knowing the concepts from this lesson lets you give AI specific instructions. Instead of a vague 'fix this,' you make vocabulary-backed requests — that is where token savings begin.
- ▸'Add appropriate TypeScript type annotations to this variable'
- ▸'Unify this mixed use of === and == to === and make the intent explicit'
- ▸'Add an unknown type and a type guard to the JSON.parse result in this code'
Why This Reduces Tokens
Without the concepts, even after receiving an AI response you still have to ask 'What does that mean?' again. That follow-up question is what eats up tokens. Learn the concept once and the conversation ends in a single exchange.