Javascript: Data Types

📄 Wiki page | 🕑 Last updated: Feb 9, 2022

Let's take a look at which data types we have available by using the typeof operator.

typeof returns the name of the datatype.

There are 7 primitive types:

typeof undefined // 'undefined'
typeof null // 'null'
typeof true // 'boolean'
typeof 42 // 'number'
typeof 42n // 'bigint' (available in ES11+)
typeof 'a' // 'string'
typeof Symbol('a') // 'symbol'

And there is a complex type object, which is everything else (including Arrays and Regex's):

typeof {} // 'object'
typeof [42] // 'object'
typeof /^myregex$/i // 'object'

It's important to mention that all primitive types are immutable. They are not objects, but they are wrapped in the wrapper objects. That enables to do things like 'mystr'.toUpperCase(), but keep in mind that those wrapper methods can`t modify the primitive, only return a new wrapped primitive.

Now that we have some idea of what we have available, let's see what we can do with that.

Variables and Scoping >


Ask me anything / Suggestions

If you have any suggestions or questions (related to this or any other topic), feel free to contact me. ℹī¸


If you find this site useful in any way, please consider supporting it.