DEV Community

Keerthana M
Keerthana M

Posted on

Data Types

Data types

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:

  1. primitive
  2. nonprimitives

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 — true or false. When coerced to numbers, they become 1 and 0 respectively. 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 an n suffix — 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]

Top comments (0)