Common JavaScript Interview Question: What are some data types in JavaScript?

Aman
1 min readFeb 16, 2022

--

Photo by Markus Spiske on Unsplash

There are 8 basic data types in JavaScript.

  1. Null
  2. Undefined
  3. Number
  4. Boolean
  5. BigInts
  6. Object
  7. String
  8. Symbol

How to remember them? Learn the mnemonic: NUNBBOSS.

Now that we know there are 8 data types, what exactly are these data types used for?

<script src=”https://gist.github.com/asingh714/b565f2361c804054343d11f72a67bf77.js"></script>

Of the 8 data types, 7 are primitive. And what exactly does “primitive” mean?

A primitive data type can contain only a single thing. 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:

<script src=”https://gist.github.com/asingh714/c909a321f3a8f76ac2f1dbb7e58fe3fa.js"></script>

The above logic makes the string “hi” look like an object because we are using a method on it. This is an illusion! JavaScript will create a temporary object when we want to use a method for a primitive type and then immediately discard it!

--

--

Aman

I make it easy for local businesses to have custom websites that attract more customers, boost search rankings, and drive revenue growth @ https://webzaz.com/