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.greeting = 'hello';
console.log(c);
console.log(d);

Output:
Object { greeting: "hello" }
Object { greeting: "hello" }

In JavaScript we can’t change what A points to, we can only add a property or change a property. (That points to that particular memory space)

Useful Resources: