A Data Type defines the kind of data a variable can hold, such as numbers, strings, booleans, or complex objects.
JavaScript is a dynamically typed language, which means variables can hold any type of data and types are determined at runtime.
JavaScript data types are broadly classified into two categories:
These are immutable (cannot be altered) and hold single values.
Primitive types are:
| Type | Description | Example |
|---|---|---|
Number |
Represents numeric values | let x = 42; |
String |
Represents text | let name = "Arun"; |
Boolean |
Represents logical true or false | let isLoggedIn = true; |
Null |
Represents an intentional absence | let address = null; |
Undefined |
Variable declared but not assigned | let email; |
Symbol |
Unique identifiers | let id = Symbol('id'); |
BigInt |
Large integers beyond Number.MAX_SAFE_INTEGER |
let big = 123n; |
const age = 25;
const pi = 3.14;
console.log(typeof age); // number✅ Interview Tip: JavaScript has only one number type (both integers and floats).
const name = "Arun";
const message = `Welcome, ${name}`;
console.log(typeof message); // string✅ Use backticks (
`) for template literals to interpolate variables.
let isLoggedIn = true;
if (isLoggedIn) {
console.log("Dashboard shown");
}✅ Used heavily in conditional logic (
if,while,for).
let address = null;
console.log(typeof address); // ⚠️ object (this is a JavaScript bug/quirk)✅
nullrepresents an intentional "no value".
let phone;
console.log(typeof phone); // undefined✅ A variable declared but not initialized is automatically
undefined.
const id = Symbol('userId');
const anotherId = Symbol('userId');
console.log(id === anotherId); // false✅ Each
Symbol()call returns a unique value, used as hidden keys in objects.
const big = 1234567890123456789012345678901234567890n;
console.log(typeof big); // bigint✅ Used when numbers exceed
Number.MAX_SAFE_INTEGER.
These store multiple values or collections and are mutable.
| Type | Description |
|---|---|
Object |
Key-value pairs |
Array |
Ordered collection |
Function |
Reusable block of code (also object) |
These are stored by reference in memory.
const fruits = ["Apple", "Banana", "Cherry"];
fruits.push("Mango");
console.log(fruits); // ["Apple", "Banana", "Cherry", "Mango"]✅ Arrays can hold mixed types, are zero-indexed, and have many useful methods (
push,map,filter, etc.).
const user = {
name: "Arun",
age: 24,
isVerified: true,
skills: ["JS", "React"]
};
console.log(user.name); // Arun✅ Objects are the backbone of JavaScript — everything is either a primitive or object.
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet("Arun")); // Hello, Arun!✅ Functions are first-class citizens in JS. They can be stored in variables, passed as arguments, and returned from other functions.
| Type | Mutable | Stored By | Example |
|---|---|---|---|
| Number | ❌ | Value | 42 |
| String | ❌ | Value | "Hello" |
| Boolean | ❌ | Value | true |
| Null | ❌ | Value | null |
| Undefined | ❌ | Value | undefined |
| Symbol | ❌ | Value | Symbol("id") |
| BigInt | ❌ | Value | 123n |
| Array | ✅ | Reference | [1, 2, 3] |
| Object | ✅ | Reference | { name: "Arun" } |
| Function | ✅ | Reference | function() {} |
- Primitive values are compared by value.
- Objects/arrays/functions are compared by reference.
typeof null === "object"is a JS bug (well known).ArrayandFunctionare special types of objects.- Use
Array.isArray()to check for arrays (nottypeof).