JavaScript: Primitive Values & Object References

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)

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.

3rd year CSE student at IIITKALYANI , enthusiastic learner and explorer