Understanding JavaScript's Data Types

JavaScript offers eight basic data types:

To easily remember them, learn the mnemonic: NUNBBOSS, which stands for Null, Undefined, Number, Boolean, BigInt, Object, String, Symbol.

Now that we know there are eight data types, let's explore what these data types are used for:

Of the eight data types, seven are primitive. The term “primitive” means that a data type can contain only a single value. All primitive types are immutable, and we cannot set properties on them.

Objects are the only non-primitive type because they are used to store collections of data and more complex entities.

You might be thinking, “Hey, but I heard that everything in JavaScript is an object! If a string is not an object, how come I can do the following:

This logic makes the string “hi” appear as if it were an object because we are using a method on it. This is an illusion! JavaScript creates a temporary object when we want to use a method for a primitive type and then immediately discards it!