Types in JS
There are 8 types in JavaScript since ES2020.
The 7 Primitive Types
In JavaScript, values whose types are primitive types are immutable: these values cannot be modified.
Here are the 7 primitive types with examples:
- Undefined (only one value for this type:
undefined
) - Null (same, only one value:
null
) - Number (
42
,0.42
,1e22
,Infinity
,NaN
) - String (
'Blimey!'
,"Ahoy!"
,`Aye`
,''
- empty string) - Boolean (
true
,false
) - Symbol (ES6 - ES2015) (
Symbol('Guaranteed unique')
) - BigInt (ES2020) (
9007199254740991n
)
The Object Type
Any other value is an object. By default, an object is mutable: its properties can be modified, removed, or added. Here are some examples:
- Object (
{}
,console
); - Function (
function () {}
,console.log
); - Array (
Array
) ([]
,[1, 2, 3]
); - Date (
new Date()
); - RegExp (
/^start.*end$/i
); - Map (
new Map()
); - Set (
new Set()
); - ...