Skip to main content

Types

1 mins 📖 

JavaScript has six primitive types. These all have default values and can be checked for using the typeof operator.

Default values:

'boolean' - false
'null' - null
'number' - 0
'string' - ''
'undefined' - void 0
'symbol' - Symbol() // new in ES6

Checking the type of a primitive:

if (typeof myPrimitive !== 'number')
throw new TypeError('Type must be a number!')