美文网首页
预编译(题目)

预编译(题目)

作者: 程序员是粉色的 | 来源:发表于2020-07-24 17:04 被阅读0次

    1.函数声明整体提升
    2.变量 声明提升
    3.一切声明的全局变量,全是window的属性

    预编译过程:
    1.创建AO对象
    2.找形参和变量声明,将变量和形参作为AO属性名,值为undefined
    3.将实参值和形参值统一
    4.在函数体里面找函数声明,值赋予函数体

    1

    function fn(a){
        console.log(a);//function a(){}
        var a=123;
        console.log(a);//123
        function a(){}
        console.log(a)//123
        var b = function(){}
        console.log(b);//function(){}
        function d(){}
    }
    fn(1)
    

    2

    function test(a,b){
        console.log(a); //1
        c=0;
        var c;
        a=3;
        b=2;
        console.log(b)//2
        function b(){}
        function d(){}
        console.log(b)//2
        
    }
        
    test(1)
    

    3

    function test(a,b){
        console.log(a);//ƒ a(){}
        console.log(b);//undefined
        var b=234;
        console.log(b);//234
        a=123;
        console.log(a);//123
        function a(){}
        var a;
        b=234;
        var b=function(){}
        console.log(a);//123
        console.log(b);//ƒ (){}
    }
    
    test(1)
    

    4

    console.log(test) //function test(test){
    function test(test){
        console.log(test) //function test(){}
        var test = 234;
        console.log(test)//234
        function test(){}
    }
    test(1);
    var test = 123
    

    5

    var global = 100;
    
    function fn(){
        console.log(global) //100
    }
    fn()
    
    globel = 100;
    function fn(){
        console.log(globel)//undefiend
        globel = 200;
        console.log(globel)//200
        var globel = 300;
    }
    fn();
    var global;
    

    6

    function test(){
        console.log(b)//undefiend
        if(a){
            var b=100;
        }
        console.log(b)//undefiend
        c=234;
        console.log(c)//234
    }
    
    var a;
    test();
    a=10;
    console.log(c)//234
    

    7

    function bar(){
        return foo;
        foo = 10;
        function foo(){}
        var foo = 11;
    }
                
    console.log(bar())      //function foo(){}  
    

    8

      var b = "boy";
       console.log(b); // boy
       function fighting(){
        
        console.log(a); //undefiend
        console.log(c);  //undefiend
        if(a === "apple"){
         a = "Alice"
        }else{
         a = "Ada"
        }
        console.log(a)  //Ada
        var a = "Andy"; 
        middle();
        function middle(){
         console.log(c++); //NaN
         var c = 100;
         console.log(++c); //101
         small();
         function small(){
          console.log(a)  //Andy
         }
        }
        var c = a = 88;
        function bottom(){
         
         console.log(this.b); //boy
         b = "baby";
         console.log(b) //baby
        }
        bottom();
        
       }
       fighting();
       console.log(b)//baby
    

    相关文章

      网友评论

          本文标题:预编译(题目)

          本文链接:https://www.haomeiwen.com/subject/mccslktx.html