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
As already mentioned in the accepted answer and the highest voted answer, primitive values are data that are stored in stack and reference values are object that are stored in heap.
But what does this actually mean? How do they perform differently in your codes?
Primitive values are accessed by value. So when you assign an variable (var a) that has a primitive value to another variable (var b), the value of the variable (a) gets copied into the new variable (b). And when you change the value of the new variable (b), the value of the original variable remain unchanged.
When you assign a variable (var x) that has a reference value to another variable (var y), the value stored in the variable (x) is also copied into the new variable (y). The difference is that the values stored in both variables now are the reference of the actual object stored in the heap. This means that, both x and y are pointing to the same object. So when you change the value of the new variable (y), the value of the original valuable (x) is also changed (because the actual object in the heap is changed).