Javascript: Data Types

📄 BetterWays.dev 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.

ℹī¸ More info


If you find this site useful in any way, please consider donating. I'm trying to keep it as clean and fast as possible - there are no ads, no affiliate links, and no analytics/tracking scripts.