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]"
Written by Shaikh Abdul Shahid
A Full-Stack Developer with experience in PHP, Laravel, JavaScript, and React.
Founder of Online Learner, sharing practical knowledge and programming tutorials.
Building and maintaining real-world web applications since 2017.
Your Feedback
Help us improve by sharing your thoughts
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
