A data type defines what kind of value a variable can hold. JavaScript is a dynamically typed language, meaning you don’t need to specify data types explicitly.
1. Categories of JavaScript Data Types
JavaScript data types are divided into two main categories:
-
Primitive Data Types
-
Non-Primitive (Reference) Data Types
2. Primitive Data Types
Primitive types store single, immutable values.
i.String
Represents text data.
✔ Strings can use single or double quotes
ii.Number
Represents integer and floating-point numbers.
Special Number values:
iii.Boolean
Represents true or false.
iv.Undefined
A variable that is declared but not assigned a value.
v.Null
Represents intentional absence of value.
⚠ typeof null returns "object" (JavaScript bug)
vi.BigInt (ES2020)
Used for very large integers.
vii.Symbol (ES6)
Used for unique identifiers.
3. Non-Primitive (Reference) Data Types
Reference types store multiple values or complex structures.
i.Object
Stores data in key-value pairs.
ii.Array
Stores multiple values in a list.
iii.Function
Functions are also objects in JavaScript.
iv.Date
Represents date and time.
4. typeof Operator
Used to check the data type.
