What are the different data types in JavaScript?
Understand the primitive and non-primitive data types in JavaScript and how they differ.
Question
What are the different data types in JavaScript?
Answer
JavaScript has two broad categories of data types: primitive and non-primitive (or reference) types.
Primitive types:
stringnumberbooleanundefinednullsymbolbigint
Non-primitive types:
object(includes arrays, functions, and dates)
Primitive values are immutable and compared by value, while non-primitives are compared by reference.
let x = 5;
let y = 5;
console.log(x === y); // true (same value)
let a = { num: 5 };
let b = { num: 5 };
console.log(a === b); // false (different references)
Real-World Example
When comparing API responses, remember that objects are compared by reference. Even two objects with identical keys and values are considered different unless they point to the same memory reference.
Quick Practice
Log the type of each of the following values using typeof:
42, 'Hello', true, null, undefined, {}, and [].
Summary
JavaScript has 7 primitive types and 1 non-primitive type (object) — knowing how they behave is key to avoiding equality and mutation pitfalls.
Is JavaScript strongly typed?
No, JavaScript is dynamically typed — variables can change type at runtime.
Stay Updated
Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.