February 10, 2001 - Passing Parameters in JavaScript
![]() |
February 10, 2001 Passing Parameters in JavaScript Tips: February 2001
Yehuda Shiran, Ph.D.
|
6 (3 is passed to the function change() where it is doubled):
<SCRIPT LANGUAGE="JavaScript">
var a = 3;
change(a);
alert(a);
function change(value) {
value = value * 2;
}
</SCRIPT>
But JavaScript does not support passing by reference. It passes its parameters by value only. A function does not have any way to know the address of its parameters, and hence cannot change the stored parameter value. The script above generates an alert box with the value of 3, as the variable a is not being changed by the function change().



