A data type refers to the kind of value a variable holds.
JavaScript is a dynamically typed language, meaning the data type is associated with the value, not the variable itself.
For example, a variable that currently holds a number can later be reassigned to a string or an object.
JavaScript broadly classifies data types into two categories:
Primitive Data Types (7)
Primitives are immutable and stored by value.
-
Number: Represents numeric values, whether integer or floating-point. Examples:
42,3.14,NaN. -
String: Represents text, enclosed in single quotes
' ', double quotes" ", or backticks` `. -
Boolean: Represents logical truth values —
trueorfalse. When coerced to numbers, they become1and0respectively. Commonly used for conditional checks and control flow. - Undefined: Indicates a declared variable that has not been assigned a value. Conceptually borrowed from Scheme.
-
Null: Represents the intentional absence of any object value (an “empty” reference). Historically inspired by Java’s
null. -
BigInt: Used for integers larger than
Number.MAX_SAFE_INTEGER(2^53 - 1), declared with annsuffix — e.g.,9007199254740993n. - Symbol: Represents unique and immutable identifiers, often used as object keys — no two symbols are ever equal.
Non-Primitive (Reference) Data Types
Non-primitive types are mutable and stored by reference.
Object: A collection of key–value pairs, where keys are strings or symbols.
Example:{ name: "Priyasha", age: 25 }Array: An ordered list of elements. Arrays in JavaScript are dynamic and actually specialized objects.
Example:[1, 2, 3]
Internally, arrays are objects optimized for indexed access. Their size and element types can change at runtime.
- Function: A callable object. Functions are first-class citizens — they can be stored in variables, passed as arguments, and returned from other functions.
- Date, RegExp, Map, Set, etc.: These are specialized object types with their own internal behaviors.
In summary, everything in JavaScript is either a primitive or an object.
Primitive values are simple and immutable, while objects are complex and mutable.
Some sources also include Date , Map , Set , and RegExp under non-primitive types, but they are best understood as specialized objects.
Top comments (0)