Javascript examples for Language Basics:Introduction
Using Local and Global Variables
<!DOCTYPE HTML> <html> <head> <title>Example</title> </head> <body> <script type="text/javascript"> var myGlobalVar = "CSS"; function myFunc(name) { var myLocalVar = "CSS"; return ("Hello " + name + ". Today is " + myLocalVar + "."); };//from ww w.j a va 2 s .c o m document.writeln(myFunc("java2s.com")); </script> <script type="text/javascript"> document.writeln("I like " + myGlobalVar); </script> </body> </html>