美文网首页
前端试题 一

前端试题 一

作者: adtk | 来源:发表于2017-06-07 12:14 被阅读0次
    //公共js
    function log(){
        console.log(...arguments);
    }
    
    //1
    log([]+[]+'f00'.split(''));//f,0,0
    
    //2
    log(new Array(5).toString());//,,,,
    
    //3
    log((true+false)>2+true);//false
    
    //true+false=1
    //2+true=3
    
    //4
    var num4=function Fn4(){
        log(typeof Fn4)
    }
    num4();//function
    log(typeof Fn4);//undefined
    
    //5
    var num5=1;
    if (function Fn5(){}) {
        num5+=typeof Fn5;
    }
    log(num5);//1undefined
    
    
    //6
    function fun(n,o){
        log(o);
        return {
            fun:function(m){
                return fun(m,n);
            }
        }
    }
    var fn1=fun(0);
        fn1.fun(1);
        fn1.fun(2);//undefined,0,0
    var fn2=fun(0).fun(1).fun(2);//undefined,0,1
    
    var fn3=fun(0).fun(1);
        fn3.fun(2);
        fn3.fun(3);//undefined,0,0,0
    
    //7
    var fn7;
    log(typeof fn7);  //function
    function fn7(x){
        return x*2
    }
    var fn7;
      log(typeof fn7);  //function
    var fn7=1;
      log(typeof fn7);  //number
    
    //函数优先级大于变量优先级
    
    //8
    var x=2,y=1;
    function fn8(){
        var x=3;
        return {
            x:x,
            fn:function(a,b){
                x=a+b;
            }
        }
    }
    var num8=fn8();
        num8.fn(4,4);
        log(num8.x,x)
    //答案:3,2
    
    //9
    var a=0,b=0;
    function A(a){
        A=function(b){
            log(a+b++)
        }
        log(a++)
    }
    A(1);//1,将A赋值新的函数,a++:先输出a,再对a+1
    A(2);//4,
    
    //10
    

    https://www.adtk.cn

    相关文章

      网友评论

          本文标题:前端试题 一

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