Using Variables and Types - Javascript Language Basics

Javascript examples for Language Basics:Introduction

Introduction

Using Local and Global Variables

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials