Call by value (Definition)

Calling functions and passing values in the arguments.

When you call by value, you are passing an immutable constant to a function. The function will create a copy locally and that copy will be accessible in a locally scoped variable having the name of the formal parameter.

However, on exit the local value is discarded leaving the original unchanged. It doesn't matter whether you pass a literal constant value or a variable containing a value. This is easier to understand if you already have a good grasp of the scope chain mechanism.

The example demonstrates this.

Example code:

   <HTML>
   <HEAD>
   </HEAD>
   <BODY>
   <SCRIPT>
   myVar = 22;
   callMe(myVar);
   document.write("<BR>");
   document.write(myVar);
   function callMe(aValue)
   {
      document.write(aValue);
      document.write("<BR>");
      aValue = 100;
      document.write(aValue);
   }
   </SCRIPT>
   </BODY>
   </HTML>

See also:Scope chain