Dev.to WebDev πŸ›  Dev πŸ‘ 1 πŸ“– 1 min read

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 tha

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]

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.