What the heck is the Primitive and Non-Primitive data type???

As a beginner, we all struggle to understand the data type in JavaScript. But it actually really easy to understand. JavaScript largely classified the data type into 2 types. Those are Primitive and Non-Primitive data type. In this article, I will describe the Primitive and Non-Primitive data type.

Primitive Data Type

In primitive data type can create or store data directly. But can not modify the value after it’s creation.

Note that the variable in which the primitive value is stored can still be reassigned to a new value shown in example 1. But the existing value can not be changed, that we can see in example 2. So a primitive value can be replaced, but it can’t be directly changed.

Example 1

Example 2

Now see what those primitive data types are :

  1. Number

Any kind of number is a number data type. That could be an integer or floating number.

2. String

A string stores a series of characters like “My name is Shakib.” A string can be any text inside double or single quotes.

3. Null

It does not exist. But not undefined either. That means you don’t want to put anything in your variable, but again you don’t want to keep it undefined. So you have to declare the null variable explicitly. Just like that cost thisIsNull = null .

4. Undefined

When you declare a variable, but you didn’t assign a value. That the variable default value is undefined.

5. Boolean

Boolean has two values. Those are: true and false.

6. Bigint

BigInt is a special numeric type that provides support for integers of arbitrary length.

7. Symbol

It’s a very peculiar data type. Once you create a symbol, its value is kept private and for internal use.

Non-Primitive Data Type

Non-primitive data can not store or create data directly. Unlike primitive data types, non-primitive data can be modified after its creation, shown in example 3. Non-primitive data is stored by reference. An object is a non-primitive data type.

Example 3


Everything in javascript is an object except primitive data. An object is a collection of properties, and a property is an association between a name(or key) and a value.

According to the object's definition, we can understand that function and array’s data type is also the object.

That is all about primitive and non-primitive data types. See you another time. :)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store