Ask any question about JavaScript here... and get an instant response.
What are the different data types in JavaScript?
Asked on Jun 21, 2025
Answer
JavaScript has several data types that can be categorized into primitive and non-primitive types. Primitive types include String, Number, Boolean, Null, Undefined, Symbol, and BigInt, while non-primitive types include Objects.
// Primitive data types
const str = "Hello, World!"; // String
const num = 42; // Number
const bool = true; // Boolean
const nothing = null; // Null
const notDefined = undefined; // Undefined
const unique = Symbol("id"); // Symbol
const bigIntNum = 9007199254740991n; // BigInt
// Non-primitive data type
const obj = { name: "Alice", age: 30 }; // ObjectAdditional Comment:
✅ Answered with JavaScript best practices.- Primitive types are immutable, meaning their values cannot be changed.
- Objects are mutable and can hold collections of values and more complex entities.
- "Symbol" is used for creating unique identifiers.
- "BigInt" is used for numbers larger than the maximum safe integer in JavaScript.
- "Null" represents the intentional absence of any object value.
- "Undefined" indicates a variable that has been declared but not assigned a value.
Recommended Links:
