JavaScript Data Types
Understand the values JavaScript can store, how primitives differ from objects, and how data moves through memory.
Learn typeof, null versus undefined, BigInt, Symbol, arrays, reference sharing, common interview questions, and practical coding patterns.
What Are Data Types?
A data type defines the kind of value a variable can hold and the operations that can be performed on it. An e-commerce product uses several types at once: a name is a string, a price is a number, inventory status is a boolean, and the product itself is an object.
Product name
"iPhone 16"
String
Price
999.99
Number
In stock
true
Boolean
Product
{ name, price }
Object
Primitive (7)
Primitives are immutable values copied independently by value.
Reference: Object
Objects are collections whose references can be shared between variables.
const name = "Muhammad Zubair";
const age = 30;
const isDeveloper = true;
let email;
const middleName = null;const user = { name: "Zubair", age: 30 };
const products = ["Laptop", "Phone"];
const today = new Date();
const tags = new Set(["aws", "javascript"]);let a = 10;
let b = a;
b = 20;
console.log(a); // 10
console.log(b); // 20const user1 = { name: "Zubair" };
const user2 = user1;
user2.name = "Ali";
console.log(user1.name); // AliMemory and typeof
Primitive assignments create independent values. Object assignments copy a reference to the same heap object, so changing one reference can be visible through another.
Stack: b → 10
Independent primitive values
Stack: user2 ─┘
Heap: { name: "Zubair" }
Shared object reference
typeof "Hello"
→ string
typeof 10
→ number
typeof []
→ object
typeof function() {}
→ function
typeof undefined
→ undefined
typeof null
→ object
Interview Questions and Best Practices
JavaScript Data Types Quiz
Choose an answer to see the explanation and check your understanding.
1. How many primitive data types does JavaScript have?
2. Which value represents an intentional empty value?
3. What does typeof null return?
4. Which type is best for integers beyond Number.MAX_SAFE_INTEGER?
5. What does typeof [] return?
6. How are primitive values copied?
7. Which type creates unique identifiers?
8. Which statement best describes a reference type?
9. What is the best way to check whether a value is an array?
10. Which example shows an unassigned variable?
Score: 0 / 10