zoukankan      html  css  js  c++  java
  • javascript当中局部变量和全局变量

    2)局部变量和全局变量 
    马克-to-win:浏览器里面 window 就是 global,通常可以省。
    nodejs 里没有 window,但是有个叫 global 的。

    例 3.2.1
    <html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    </head>
    <script>
    /* 马克-to-win:有var无var, 在function外是一样的,都是全局的,在function里面时,var是局部的,而无var时是代表全局的*/   
        var testVar = "全量";
        document.writeln("window.testVar is" + window.testVar+testVar);
        var testqVar = "全量q";
    /*如不屏蔽下句话,程序直接停在这了,因为出错了,不认识testGlobal,得把下一句和下下句换一下位置,就ok了 */
      //  document.writeln("testGlobal is" + testGlobal);
        testGlobal = "全量global";
        document.writeln("abc is" + abc);
        var abc;
        testGlobalInVar = "全量globalInVar";
        function testSco()
        {
            var lll = "qqq";
            var testVar = "局量"; //此testVar非外面的testVar
            testqVar = "全量qchange"; //此testqVar就是外面的testqVar
            testGlobal = "全量globalchange";
            var testGlobalInVar = "局量global";//此testGlobalInVar非外面的testGlobalInVar
            /*local variable is stronger than global variable.so "testVar" in the following statement means local variable.*/
            document.writeln(testVar);
            document.writeln(testqVar);
            document.writeln("testGlobalInVar is " + testGlobalInVar);
        }
        testSco();
        document.writeln("second test is " + testVar);
        document.writeln("second testqVar is " + testqVar);
        document.writeln("testGlobal is " + testGlobal);
        document.writeln("testGlobalInVar is " + testGlobalInVar);
    </script>

    更多请见:https://blog.csdn.net/qq_44594249/article/details/99864142

  • 相关阅读:
    HDU 1097 a hard puzzle
    HDU 4588 Count The Carries
    不想用锐捷怎么办?锐捷出问题|锐捷不能用怎么办?用menohust代替吧
    线段树及其变种的相关资料(不定期更新)
    UVa 10075
    UVa 1301
    UVa 10256
    UVa 1453
    计算几何相关资料+题目推荐(不定期补充)
    UVa 11524
  • 原文地址:https://www.cnblogs.com/renzhe111/p/12131571.html
Copyright © 2011-2022 走看看