JavaScript Primitive Types
Primitive Values
Primitive values are the simplest values in JavaScript.
Primitive values are not objects.
JavaScript has seven primitive types.
The Primitives
| Type | Example | typeof |
|---|---|---|
| string | "Hello" |
"string" |
| number | 123 |
"number" |
| boolean | true |
"boolean" |
| bigint | 123n |
"bigint" |
| symbol | Symbol() |
"symbol" |
| undefined | undefined |
"undefined" |
| null | null |
"object" |
Note
The result of typeof null is "object".
This is a historical JavaScript behavior (error).
Primitive Values Are Not Objects
Primitive values are not objects.
Wrapper Objects
JavaScript provides wrapper objects for some primitive types.
| Primitive Type | Wrapper Object |
|---|---|
| string | String |
| number | Number |
| boolean | Boolean |
Primitive values can use methods provided by their wrapper objects.
Primitive Types Overview
String
"Hello"
'Hello'
`Hello`
Strings represent text values.
Learn more about string values
Number
123
3.14
-10
Numbers represent numeric values.
Learn more about number values
Boolean
true
false
Booleans represent true or false.
Learn more about boolean values
BigInt
123n
9007199254740993n
BigInt values represent large integers.
Learn more about bigint values
Symbol
Symbol()
Symbol("id")
Symbols represent unique identifiers.
Learn more about symbol values
Undefined
let x;
Undefined represents the absence of a value.
Null
let x = null;
Null represents the intentional absence of a value.