Dave's Brain

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.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.