<html> <head> <title>A Scoping Example</title>
<script type = "text/javascript"> <!-- var x = 1; //global variables var y = 4;
function start() { var x = 9; //local variables var z = 2; document.writeln( "values are " + x + y + z); Junk(); // call the function Junk document.writeln( "<p>values are " + x + y + z + "<p>"); Stuff(); document.writeln( "<p>values are " + x + y + z + "<p>"); }
function Junk() { var z = 6; document.writeln( "<p>Jvalues are " + x + y + z + "<p>"); y++; // same as y = y + 1; Stuff(); document.writeln( "<p>Jvalues are " + x + y + z + "<p>"); }
function Stuff() { var y = 7; var z = 1; document.writeln( "<p>Svalues are "+ x + y + z + "<p>"); x=x+2; } // --> </script> </head> <body onload = "start()"></body>
</html>
|