What Are the Data Types Supported by JavaScript?
JavaScript variables can hold different types of data values. Understanding these is fundamental for every developer. JavaScript has two main categories of data types:
1. Primitive Data Types (Immutable)
- String: Text data
let name = "John";
- Number: Both integers and decimals
let age = 25; let price = 99.99;
- Boolean: true/false
let isActive = true;
- Undefined: Uninitialized variable
let x; // undefined
- Null: Intentional absence of value
let user = null;
- Symbol (ES6): Unique identifiers
let id = Symbol('unique');
- BigInt (ES2020): Large integers
let bigNum = 9007199254740991n;
2. Non-Primitive Data Types (Mutable)
- Object: Key-value pairs
let person = { name: "John", age: 30 };
- Array: Ordered lists
let colors = ["red", "green", "blue"];
- Function: Callable objects
function greet() { console.log("Hello!"); }
Type Checking
Use typeof
operator:
typeof "Hello" // "string"
typeof 42 // "number"
typeof true // "boolean"
Special Cases
typeof null // "object" (historical bug)
typeof [] // "object"
typeof function() {} // "function"
Pro Tip: For precise type checking, use:
Array.isArray([]) // true
Object.prototype.toString.call(null) // "[object Null]"
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Terms Disclaimer About Us Contact Us
Copyright 2023-2025 © All rights reserved.