Jump to content

Passing Parameters By Reference?


davej

Recommended Posts

So in what cases are you passing a reference to a function? For some odd reason the forum search engine seems to puke on this topic. Strings are passed by value, right?What, if anything, is not passed by value? Thanks.

Link to comment
Share on other sites

I believe that functions are always passed by reference, although they could act the same as objects. Primitive types are always passed by value. Objects are a little strange, objects are passed by value but the value is a reference. If you pass an object and change properties of it, those properties are also changed outside the function (as if it's a reference). If you pass the object and overwrite it, the object outside of the function does not change, as if it was passed by value. There's an example which illustrates that in the first answer here: http://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...