Mega Code Archive

 
Categories / JavaScript DHTML / Language Basics
 

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>