February 2018
Intermediate to advanced
298 pages
8h 22m
English
When we assign an object to a variable, the reference of the object is what the variable holds and not the object itself. So, when assigning an object to a constant variable, the reference of the object becomes constant to that variable and not to the object itself. Therefore, the object is mutable. Consider this example:
const a = { name: "Mehul"};console.log(a.name);a.name = "Mohan";console.log(a.name);a = {}; //throws read-only exception
The output of the preceding code is:
MehulMohan<Error thrown>
In this example, the a variable stores the address (that is, reference) of the object. So the address of the object is the value of the a variable, and it cannot be changed. But the object is mutable. ...
Read now
Unlock full access