Data Types
Data Types in JavaScript
Every value in JavaScript belongs to a specific data type. Understanding how JavaScript categorizes, stores, and evaluates data types is essential for debugging type coercion and memory references.
1. The Two Major Categories of Data Types
JavaScript divides its data types into two distinct categories:
+-----------------------------------------------------------------------------+ | JAVASCRIPT DATA TYPES | +-----------------------------------------------------------------------------+ | | | 1. PRIMITIVE TYPES (7 Types) 2. REFERENCE TYPES (Objects) | | - Stored directly in the Call Stack - Stored in the Memory Heap | | - Immutable (cannot be altered in place) - Mutable | | - Compared by VALUE - Compared by REFERENCE | | | | * string * number * boolean * Object | | * null * undefined * symbol * Array (Specialized object) | | * bigint * Function (Callable object) | +-----------------------------------------------------------------------------+
2. Deep Dive: The 7 Primitive Types
1. string
Textual data enclosed in single quotes '...', double quotes "...", or backticks `` ... ``:
2. number
Represents both integers and floating-point numbers (64-bit IEEE 754 floats):
3. bigint
For arbitrarily large integers beyond JavaScript's safe integer limit ($2^{53} - 1$ or 9,007,199,254,740,991):
4. boolean
Logical values: strictly true or false:
5. undefined
A variable that has been declared, but has not yet been assigned a value:
6. null
Represents the intentional absence of any object value:
7. symbol (ES6)
A unique, immutable identifier used as unique object keys:
3. The typeof Operator and the Famous Bug
Use the typeof operator to inspect the data type of any variable:
0. null was represented as a NULL pointer (0x00), causing typeof null to incorrectly return "object". This bug cannot be fixed now because doing so would break millions of legacy websites!4. Primitives (By Value) vs. Reference Types (By Reference)
Understanding this difference prevents 90% of beginner logic bugs:
Primitives are Copied by Value:
Objects are Copied by Memory Reference:
Practice Quiz
typeof null in JavaScript?undefined and null?let obj2 = obj1;)?Comments and Best Practices
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Variables: var, let, const | Comments and Best Practices |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.