How do I pass a function by reference and then call it?

Actually JS functions, just like Java’s, are ALWAYS pass by value, regardless it’s a primitive or object datatype.

When we pass a variable as a single argument to a function, the current value stored in that variable is read, and then the invoked function’s receiving parameter is initialized w/ a copy of that read value.

B/c a function’s parameter can only receive a copy of the current value stored in a passed variable, reassigning another value to that local parameter won’t replace the value stored in the original passed variable.

Obviously if that value happens to be an object, mutating its properties via the local parameter will reflect on the original passed variable as long as that variable still stores that same object value.

3 Likes