Browse - Programming Tips - Are javaScript parameters passed by reference or value?

Date: 2009apr24
Language: javaScript

Q.  Are javaScript parameters passed by reference or value?
Can I control it?

A.  Objects are passed by reference and primitive types are passed by value.
Primitives types are: Undefined, Null, Boolean, Number, and String.

So...

If you want to pass a primitive type by reference ==> wrap it in an object.

If you want to pass an object by value ==> assign it to a temporary
variable and pass that in.