JavaScript: Primitive Values & Object References

Sweta Barnwal
2 min readJun 19, 2021

JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript:

  1. Primitive values
  2. Non-primitive values (object references)

Data types that are known as primitive values in JavaScript are numbers, strings, booleans, bigint and undefined and symbols . Objects such as functions and arrays are referred to as non-primitive values.

The fundamental difference between primitives and non-primitive is that primitives are immutable and non-primitive are mutable.

Primitives are known as being immutable data types because there is no way to change a primitive value once it gets created. They are compared by value. Two values are strictly equal if they have the same value.

Non-primitive values are mutable data types. The value of an object can be changed after it gets created. Objects are not compared by value. This means that even if two objects have the same properties and values, they are not strictly equal. The same goes for arrays. Even if they have the same elements that are in the same order, they are not strictly equal.

Non-primitive values can also be referred to as reference types because they are being compared by reference instead of value. Two objects are only strictly equal if they refer to the same underlying object.

--

--