Primitive and Reference Values
Primitive and Reference values are stored in memory. Primitive values are stored on the Stack and Reference values are stored on the Heap.
Primitive types include numbers, strings, Booleans, null, undefined and symbols.
Most of the time, a primitive value is represented directly at the lowest level of the language implementation.
Reference types include all types of objects, object literals, arrays, functions, dates and all other objects.
//primitive values
let scoreOne = 50;
let scoreTwo = scoreOne;
console.log(`scoreOne: ${scoreOne}`, `scoreTwo: ${scoreTwo}`);
//answer: scoreOne: 50 scoreTwo: 50
scoreOne = 100;
console.log(`scoreOne: ${scoreOne}`, `scoreTwo: ${scoreTwo}`);
//answer: scoreOne: 100 scoreTwo: 50
//reference values
userOne = { name: 'mike', age: 30 };
userTwo = userOne;
console.log(userOne, userTwo);
//answer: {name: "mike", age: 30} {name: "mike", age: 30}
userOne.name = 'peter';
console.log(userOne, userTwo);
//answer: {name: "peter", age: 30} {name: "peter", age: 30}