In JavaScript, there are several built-in data types, which can be categorized into primitive and non-primitive (reference) types.
1. Primitive Data Types
Primitive types are immutable and are directly assigned by value.
- String: Represents a sequence of characters. Example:
- Number: Represents both integer and floating-point numbers. Example:
- BigInt: Used for large integers that are beyond the range of the
Number
type. Example: - Boolean: Represents a value of either
true
orfalse
. Example: - undefined: Represents a variable that has been declared but not assigned a value. Example:
- null: Represents an intentional absence of any object value. Example:
- Symbol: Represents a unique and immutable value, often used as object property keys. Example:
2. Non-Primitive (Reference) Data Types
Non-primitive types are mutable and assigned by reference.
- Object: Represents a collection of key-value pairs. Example:
- Array: A special type of object used to store ordered collections. Example:
- Function: Functions are a type of object in JavaScript, and can be assigned to variables, passed as arguments, etc. Example:
These data types cover the range of types you'll use in JavaScript to handle different kinds of data.