I read a book called \"Professional Javascript for web developer\" and it says: \"Variable is assigned by Reference value or Primitive Value. Reference values are objects st
Variable are segments of memory (RAM) which the javascript engine reserves to hold your data. Within these variables can be stored 2 kinds of values:
When a primitive value gets assigned to a variable the data (values of the bits) just copied. For example:
Primitive values:
let num1 = 10;
// What happens here is that the bits which are stored in the memory container
// (i.e. variable num1) are literally copied into memory container num2
let num2 = num1;
Reference values:
let objRef1 = {prop1: 1}
// we are storing the reference of the object which is stored in objRef1
// into objRef2. Now they are pointing to the same object
let objRef2 = objRef1;
// We are manipulating the object prop1 property via the refernce which
// is stored in the variable objRef2
objRef2.prop1 = 2;
// The object which objRef1 was pointing to was mutated in the previous action
console.log(objRef1);