JS - Pass by Value or by Reference
Primitives types such as: Strings, numbers, boolean, undefined, null and symbol (ES6) are passed by value (You are passing a COPY) All objects (including functions, because yes, functions are objects) are passed by Reference (Something that points to the real object (same memory space)) Passing by value: "use strict" let a = 1; function foo(a) { a = 2; } foo(); console.log(a); Output: 1; Passing by reference: "use strict" let c = { greeting: 'hi' }; let d; d = c; c.
Posted
#JS