16快速识别预解释的结果

  • 快速查错方法
点击能查看在哪行报错.png
点击能查看在哪行报错2.png
  • 16快速识别预解释的结果
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>16快速识别预解释的结果</title>
    <script>
        // var a = 25;
        //
        // function abc() {
        //     // var a;
        //     alert(a);//undefined
        //     var a = 10;
        //     // a = 10;
        // }
        //
        // abc();//alert(a);//undefined
        // // console.log(a);//25




        // 如果变量和函数同名的话,函数优先
        // var a;
        // console.log(a);//a  是函数代码
        // function a() {
        //     console.log('aaaaa');
        // }
        // var a = 1;
        // console.log(a);//1



        // // var a;
        // // a=18;//作用域链,所以先函数里后外
        // var a = 18;
        // // function f1() {
        // //     var b = 9;
        // //     console.log(a);//undefined
        // //     console.log(b);//9
        // //     var a = '123';
        // // }
        // f1();// undefined  9
        // function f1() {
        //     // var b;
        //     // var a
        //     // b = 9;
        //     var b = 9;
        //     console.log(a);//undefined
        //     console.log(b);//9
        //     var a = '123';
        // }




        function f1() {
            var a;//a用var声明了并且在函数里面,是局部变量,所以会报错
            // a=b=c=9;
            a=9;
            //隐式全局变量
            b=9;
            c=9;
            // var a = b = c = 9;
            console.log(a);//9
            console.log(b);//9
            console.log(c);//9
        }
        f1();
        console.log(c);//9
        console.log(b);//9
        console.log(a);//报错
        // function f1() {
        //     var a = b = c = 9;
        //     console.log(a);//9
        //     console.log(b);//9
        //     console.log(c);//9
        // }



        // 随机数
        // console.log(parseInt(Math.random()*57+1))
    </script>

</head>
<body>

</body>
</html>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 交代下这篇文章的背景,开完会刚回到家。。。 想必不言而喻了,像我一样刚到家的不在少数,而这个点到家的上班族...
    问艺阅读 4,132评论 3 2
  • 它知道她的身体不会永远存在在这里,也不需要一直存在。正如她过去曾说过的一句话:每时每刻都在生,每时每刻都在死。 曾...
    心形的星星阅读 1,306评论 0 1