<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> new document </title>
<Meta name = "generator" content = "editplus">
<Meta name = "author" content = "">
<Meta name = "keywords" content = "">
<Meta name = "Description" content = "">
</Head>
<Body>
<SCRIPT type = "text/JavaScript">
Testvar1 ();
Testvar ();
Alert (TEST); // output hello!
Alert (test1); // an error is reported in the output. test1 is not defined.
Function testvar1 ()
{
VaR test1 = "hello1! ";
}
Function testvar ()
{
Test = "Hello! ";
}
</SCRIPT>
</Body>
</Html>
Analyze the variables in JavaScript Functions through the instance program, without the difference between var declaration and VAR declaration.
Conclusion:
1. variables declared by VAR are equivalent to global variables in JavaScript Functions, that is, they are visible outside JavaScript functions. However, before using this variable, you must call the corresponding JavaScript function.
2. the variables declared by VAR in JavaScript Functions are equivalent to local variables, and their visibility is only within the corresponding JavaScript function.
3. We recommend that you display the definition variables before use, so that the program can be readable and maintainability. Try not to use the method in the first article.