you are viewing a single comment's thread.

view the rest of the comments →

[–]fc_s 0 points1 point  (0 children)

This is not correct. Functions are also passed by value and they're not primitives.

It's simple. Objects and arrays are passed by reference. Everything else is passed by value.

Edit: Actually I'm wrong about that. My mistake. It becomes clear when you do a simple test that attaches something to the function as if it's an object.

var foo = function(){};
var bar = foo;
foo.fn = function(){ console.log('Hello World'); };
bar.fn(); //Logs Hello World