Use of Global and Local Variables : Variable Definition « Language Basics « JavaScript DHTML






Use of Global and Local Variables

  

<HTML>
<HEAD>
<TITLE>Global and Local Variables</TITLE>
<SCRIPT LANGUAGE="JavaScript"><!--
function displaySquared(y) {
    var x = y * y
    document.write(x+"<BR>")
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript"><!--
for(x=0;x<10;++x)
 displaySquared(x)
// -->
</SCRIPT>
</BODY>
</HTML>

           
         
    
  








Related examples in the same category

1.The Effects of Local and Global Variables
2.Event Handler with Multiple Statements in Attribute Value
3.Global and Local Variable Scope Demonstration
4.Global Versus Local Scope of a Variable
5.Variable scope
6.Variable scoping
7.Get the type of a variable
8.Global scope and page scope
9.String value is passed by value, while the array is passed by reference