I know that objects in Javascript are copied/passed by reference. But what about functions?
I was trying out this code when I jumped to something confusing. Here is the code snippet:
x = function() { console.log('hey 1'); }
y = x;
x = function() { console.log('hey 2'); }
y; // Prints function() { console.log('hey 1'); }
If functions like objects are copied/passed by reference, why y is not updated to print 'hey 2'?
If this behavior is because 'x' is assigned with a brand new function, is there any way for variable 'y' to the newly assigned function when x changes?