Data types

JavaScript has two main categories of data types:

  • Primitive Data Types (immutable, stored by value)
  • Non-Primitive (Reference) Data Types (mutable, stored by reference)

1. Primitive Data Types

Primitive types hold single values and are immutable.
Data TypeDescriptionExample
NumberRepresents integers and floating-point numberslet age = 25;
StringRepresents text (sequence of characters)let name = "Alice";
BooleanRepresents true or falselet isActive = true;
UndefinedA variable that has been declared but not assigned a valuelet x;
NullRepresents an empty or non-existent valuelet data = null;
Symbol (ES6)Unique and immutable identifierlet id = Symbol("id");
BigInt (ES11)For numbers larger than 2^53 - 1let bigNum = 12345678901234567890n;

Example:

let num = 42;             // Number
let text = "Hello";       // String
let isReady = false;      // Boolean
let emptyValue = null;    // Null
let notAssigned;          // Undefined
let uniqueID = Symbol();  // Symbol
let largeNumber = 123n;   // BigInt

2. Non-Primitive (Reference) Data Types

Reference types hold collections of values and are mutable.

Data TypeDescriptionExample
ObjectCollection of key-value pairs{ name: "Alice", age: 25 }
ArrayOrdered list of values[1, 2, 3, "hello"]
FunctionBlock of reusable codefunction greet() { console.log("Hi!"); }

Example: 

// Object
let person = { name: "Alice", age: 25 };
// Array
let numbers = [10, 20, 30, 40];
// Function
function greet() {
    return "Hello, World!";
}

Checking Data Types

You can check a variable’s data type using typeof:

console.log(typeof 42);         // "number"
console.log(typeof "Hello");    // "string"
console.log(typeof true);       // "boolean"
console.log(typeof undefined);  // "undefined"
console.log(typeof null);       // "object" (JavaScript bug)
console.log(typeof {});         // "object"
console.log(typeof []);         // "object"
console.log(typeof function(){}); // "function"
Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2025 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz