scopeexample.htm

来自「这是javascript高级程序设计的源码」· HTM 代码 · 共 28 行

HTM
28
字号
<html>
    <head>
        <title>Scope Example</title>
    </head>
    <body>
        <p>In this example, the <code>var</code> statement isn't used to define
        the variable <code>sMyFirstName</code>, so it is created as a variable
        at the <code>window</code> scope. This is proved because the second function
        can also access the variable and display it in an alert.</p>
        <script type="text/javascript">

            function sayFirstName() {
                sMyFirstName = "Nicholas";
                alert(sMyFirstName);
            }
            
            function sayFirstNameToo() {
                alert(sMyFirstName);
            }
            
            sayFirstName();
            sayFirstNameToo();
        </script>
    </body>
</html>


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?