Data Types0%

Data Types

Beginner12 min read•Updated: Jul 11, 2026
Study Materials

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:

Visual Architecture Blueprint
+-----------------------------------------------------------------------------+
|                          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 `` ... ``:

JavaScript
let name = "Sumit";
let greeting = `Hello, ${name}!`; // Template literal

2. number

Represents both integers and floating-point numbers (64-bit IEEE 754 floats):

JavaScript
let age = 25;
let price = 99.99;
let negative = -15;
// Special numeric values:
let infinity = 1 / 0; // Infinity
let notANumber = "apple" / 2; // NaN (Not-a-Number)

3. bigint

For arbitrarily large integers beyond JavaScript's safe integer limit ($2^{53} - 1$ or 9,007,199,254,740,991):

JavaScript
let bigNumber = 9007199254740991123456789n; // Suffix with 'n'

4. boolean

Logical values: strictly true or false:

JavaScript
let isEnrolled = true;
let hasPaid = false;

5. undefined

A variable that has been declared, but has not yet been assigned a value:

JavaScript
let score;
console.log(score); // undefined

6. null

Represents the intentional absence of any object value:

JavaScript
let selectedCourse = null; // Deliberately empty for now

7. symbol (ES6)

A unique, immutable identifier used as unique object keys:

JavaScript
const id1 = Symbol("id");
const id2 = Symbol("id");
console.log(id1 === id2); // false (Every symbol is globally unique!)

3. The typeof Operator and the Famous Bug

Use the typeof operator to inspect the data type of any variable:

JavaScript
typeof "Hello" // "string"
typeof 42 // "number"
typeof true // "boolean"
typeof undefined // "undefined"
typeof 100n // "bigint"
typeof Symbol() // "symbol"
typeof { a: 1 } // "object"
typeof [1, 2, 3] // "object" (Arrays are objects in JS!)
typeof function(){}// "function"
Important Warning
[!WARNING] The Famous JavaScript Bug: ```javascript typeof null; // "object" ``` In the original 1995 JavaScript implementation, values were stored with a type tag. The tag for objects was 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:

JavaScript
let a = 10;
let b = a; // b receives an independent copy of value 10
b = 20;
 
console.log(a); // 10 (Untouched!)
console.log(b); // 20

Objects are Copied by Memory Reference:

JavaScript
let user1 = { name: "Sumit" };
let user2 = user1; // user2 points to the SAME memory address in the heap!
 
user2.name = "Rahul";
 
console.log(user1.name); // "Rahul" (user1 was modified because both point to same object!)

Interactive Quiz

Practice Quiz

Question 1
How many primitive data types exist in modern JavaScript?
Question 2
What is the result of running typeof null in JavaScript?
Question 3
What is the difference between undefined and null?
Question 4
What happens when you assign an object variable to a new variable (let obj2 = obj1;)?
Question 5
Which primitive data type allows representing integers larger than $2^{53} - 1$?
Next Lesson

Comments and Best Practices

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext