zoukankan      html  css  js  c++  java
  • in window js 未定义和undifined的区别

    浏览器报错:未定义和undifined不是同一概念,前者是没有申明,后者是没有赋值。


    1:

    <html>
        <body>
            <script>
                if(!("a" in window)){
                    var a = 1;
                }
                alert(a);//undifined

                function b(){
                    var c = 2;
                }
                alert(b);//函数b
                //alert(c);//报错 c未定义
                alert("c" in window);//false
                alert(c);//报错 c未定义
            </script>
        </body>
    </html>

    2:

    <html>
        <body>
            <script>
                var a = 1
                b = function a(x){
                    x && a(--x);
                };
                alert(a);//1
            </script>
        </body>
    </html>

    3:

    <html>
        <body>
            <script>
                if(!("" in window)){
                    var a = 1;
                }
                alert(a);//1
            </script>
        </body>
    </html>

    4:

    <html>
        <body>
            <script>
                var d;
                alert(d);//undifined
                var a = 1;
                b = function a(x){
                    x && a(--x);
                };
                alert(a);//1
            </script>
        </body>
    </html>




    @江西-小若 总结

  • 相关阅读:
    [vue]vue路由篇vue-router
    [vue]spa单页开发及vue-router基础
    [css]table的拆分
    [sh]md5sum接变量,find排除,sh判断文件存在
    [vue]通过watch实现数据双向绑定
    [django]form不清空问题解决
    [vue]实现父子组件数据双向绑定
    springboot2.0 如何异步操作,@Async失效,无法进入异步
    kafka搭建笔记
    Springboot2.x+shiro+redis(Lettuce)整合填坑
  • 原文地址:https://www.cnblogs.com/pangblog/p/3320015.html
Copyright © 2011-2022 走看看