January 2020
Intermediate to advanced
470 pages
11h 13m
English
If the mutations don't happen because of using some JavaScript methods, then we might want to attempt to use const definitions, but that just won't work. In JavaScript, a const definition means that the reference to the object or array cannot change (you cannot assign a different object to it) but you can still modify the properties of the object itself. We can see this in the following code:
const myObj = {d: 22, m: 9};console.log(myObj);// {d: 22, m: 9}myObj = {d: 12, m: 4};// Uncaught TypeError: Assignment to constant variable.myObj.d = 12; // but this is fine!myObj.m = 4;console.log(myObj);// {d: 12, m: 4}
You cannot modify the value of myObj by assigning it a new value, but you can modify the current value of myObj so that ...