JavaScript Fundamentals

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

JavaScript Data Type Map

Primitive (7)

String
Number
BigInt
Boolean
Undefined
Null
Symbol

Primitives are immutable values copied independently by value.

Reference: Object

Array
Function
Date
Map
Set
Custom object

Objects are collections whose references can be shared between variables.

Primitive values
const name = "Muhammad Zubair";
const age = 30;
const isDeveloper = true;

let email;
const middleName = null;
Objects and collections
const user = { name: "Zubair", age: 30 };
const products = ["Laptop", "Phone"];
const today = new Date();
const tags = new Set(["aws", "javascript"]);
Primitive copy
let a = 10;
let b = a;
b = 20;

console.log(a); // 10
console.log(b); // 20
Reference sharing
const user1 = { name: "Zubair" };
const user2 = user1;
user2.name = "Ali";

console.log(user1.name); // Ali

Memory 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: a → 10
Stack: b → 10

Independent primitive values
Stack: user1 ─┐
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

Why is typeof null object? It is a historical compatibility quirk.
Why is an array an object? Arrays inherit object behavior and typeof reports object.
Use Array.isArray(value) to detect arrays.
Use null intentionally; use undefined for an unassigned value.
Use BigInt for integers beyond Number's safe range.
Avoid comparing objects directly: {} === {} is false because references differ.
Use strict equality and avoid implicit type coercion.
Remember: primitives are copied by value; objects share references.
Practice quiz

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