By Reference: with Objects (incl. functions)
1 2 3 4 5 6 7 8 9 10 |
var a, b; var a = { myObj: "value" }; b = a; // b points to same location in memory console.log(a); // Output: Object {myObj: "value"} console.log(b); // Output: Object {myObj: "value"} // EXCEPT when you create a new object with equals operator var a = { myObj: "value2" }; console.log(a); // Output: Object {myObj: "value2"} |
By Value: with primitive types
1 2 3 4 5 6 |
var a = true; var b; var b = a; //b is now a COPY of a - a new value so console.log(a === b); // <- true |