Understanding JavaScript Data Types: A Simple Guide with Examples
JavaScript Data Types 2025 – JavaScript is one of the most popular programming languages, mainly used for building interactive websites. Like every language, JavaScript also deals with data, and data comes in different forms. These different forms of data are called data types.

By the end of this article, you will understand:
- What data types are in JavaScript
- Different types of data in JavaScript
- Real-life examples to make learning easier
- FAQs related to JavaScript data types
Let’s get started!
What Are Data Types in JavaScript?
Think of data types like different kinds of containers in your kitchen. Some containers hold water (liquid), some hold rice (solid grains), and others hold sugar (crystals). In the same way, JavaScript has different types of data storage.
JavaScript data types define the kind of values that can be stored and manipulated in a program. These data types help JavaScript understand how to handle different kinds of information.
Types of Data in JavaScript
JavaScript has two main types of data:

- Primitive Data Types (Simple data)
- Non-Primitive Data Types (Complex data)
1. Primitive Data Types
Primitive data types are the most basic types in JavaScript. They store simple values and are immutable (cannot be changed).
There are seven primitive data types in JavaScript:

a) Number
Numbers in JavaScript include both integers (whole numbers) and floating-point numbers (decimals).
Example:
let age = 25; // Integer
let price = 99.99; // Decimal
Real-Life Example: Imagine you are buying a burger. The price (e.g., $4.99) is a number.
b) String
A string is a sequence of characters, usually written inside quotes (""
, ''
, or “ `).
Example:
let name = "Alice";
let greeting = 'Hello, world!';
Real-Life Example: Your name, address, or any text message you send on WhatsApp is a string.
c) Boolean
A Boolean represents one of two values: true or false.
Example:
let isRaining = true;
let isSunny = false;
Real-Life Example: The question “Is the light on?” has two answers: Yes (true) or No (false).
d) Undefined
A variable that is declared but not assigned a value is undefined
.
Example:
let city;
console.log(city); // Output: undefined
Real-Life Example: You book a flight but don’t select a meal. Your meal preference is undefined.
e) Null
null
is a special value in JavaScript that represents “nothing”.
Example:
let car = null;
Real-Life Example: If you remove an app from your phone, its data becomes null.
f) Symbol
A Symbol
is a unique and immutable value used mainly for object properties.
Example:
let uniqueID = Symbol('id');
Real-Life Example: Think of a fingerprint—it is unique to every person, just like a symbol in JavaScript.
g) BigInt
The BigInt
data type is used to store numbers larger than the standard limit for JavaScript numbers.
Example:
let bigNumber = 9007199254740991n;
Real-Life Example: Large bank account balances or population numbers often need BigInt.
2. Non-Primitive (Reference) Data Types
Non-primitive data types are more complex and can hold multiple values. These include:

a) Object
Objects are collections of key-value pairs. They can store multiple related values.
Example:
let person = {
name: "John",
age: 30,
city: "New York"
};
Real-Life Example: A contact in your phone (name, number, email) is stored as an object.
b) Array
Arrays store multiple values in a single variable.
Example:
let fruits = ["Apple", "Banana", "Cherry"];
Real-Life Example: A shopping list where you write multiple items.
c) Function
A function is a block of reusable code that performs a specific task.
Example:
function greet(name) {
return "Hello, " + name + "!";
}
console.log(greet("Alice"));
Real-Life Example: A coffee machine follows a function: “Press a button → Make coffee”.
How to Check Data Types in JavaScript?
You can use the typeof
operator to check the type of a variable.
Example:
console.log(typeof 42); // "number"
console.log(typeof "Hello"); // "string"
console.log(typeof true); // "boolean"
console.log(typeof null); // "object" (this is a known JavaScript quirk)
console.log(typeof undefined); // "undefined"
console.log(typeof {name: "John"}); // "object"
console.log(typeof [1,2,3]); // "object" (arrays are special objects)
FAQs About JavaScript Data Types 2025
1. What is the difference between null
and undefined
?
null
means a variable exists but has no value.undefined
means a variable is declared but not assigned a value.
2. Why is typeof null
an “object”?
This is a known mistake in JavaScript. Originally, JavaScript had a bug in its type-checking mechanism, and it was never corrected to maintain compatibility.
3. What is the difference between primitive and non-primitive data types?
Primitive data types hold single, simple values and are immutable (cannot be changed).
Non-primitive data types store collections of values and are mutable.
4. Can we change the value of a primitive type?
No. When you change a primitive value, you are actually creating a new value, not modifying the original.
5. What happens if I store an object inside another object?
You create a nested object, which is useful for organizing complex data.
Example:let student = { name: "Alice", subjects: { math: 90, science: 85 } };
Summary
- JavaScript has primitive data types (Number, String, Boolean, Undefined, Null, Symbol, BigInt).
- JavaScript has non-primitive data types (Object, Array, Function).
- Use
typeof
to check the data type of a variable. null
andundefined
are different:null
means no value,undefined
means not assigned.
Understanding JavaScript data types is essential for writing clean and error-free code. By knowing which data type to use, you can store and manage data efficiently!
A Beginner’s Guide to JavaScript Loops with Real-Life Examples