String value is passed by value, while the array is passed by reference : Variable Definition « Language Basics « JavaScript DHTML






String value is passed by value, while the array is passed by reference

   
<html>
<head>
<title>Pass Me</title>
</head>
<body>
<script type="text/javascript">
function alterArgs(strLiteral, aryObject) {
   strLiteral = "new value";
   aryObject[aryObject.length] = "three";
}

var str = "old value";
var ary = new Array("one","two");

alterArgs(str,ary);

document.writeln("string literal is " + str + "<br /> ");
document.writeln("Array object is " + ary);

</script>
</body>
</html>

   
    
    
  








Related examples in the same category

1.The Effects of Local and Global Variables
2.Use of Global and Local Variables
3.Event Handler with Multiple Statements in Attribute Value
4.Global and Local Variable Scope Demonstration
5.Global Versus Local Scope of a Variable
6.Variable scope
7.Variable scoping
8.Get the type of a variable
9.Global scope and page scope