美文网首页
几个习题

几个习题

作者: ads | 来源:发表于2020-04-02 22:46 被阅读0次
    var a = 100
    function foo() {
        console.log(a)
    }
    function bar(fn) {
        var a = 200
        fn()
    }
    bar(foo)
    // 100
    
    let a = []
    for(let i = 0; i < 10; i++) {
        a[i] = function() {
            console.log(i)
        }
    }
    a[6]()
    // 6 
    // undefined
    // 10 
    // undefined
    
    function show(){
            var a=b=5;
        }
        show();
        console.log(typeof a == 'undefined');//判断变量a是不是未定义 true
        console.log(typeof b == 'undefined');//判断变量b是不是未定义 false b的值是5
    (function() {
        var a=b=5;
    })()
    console.log(a, b)
    // ReferenceError: a is not defined
    // b = 5
    
    var x = 20
    var a = {
        x: 15,
        fn: function() {
            var x = 30 
            return function() {
                return this.x
            }
        }
    }
    console.log(a.fn())
    console.log((a.fn())())
    console.log(a.fn()())
    console.log((a.fn())() == a.fn()())
    console.log(a.fn().call(this))
    console.log(a.fn().call(a))
    
    const promise = new Promise((resolve, reject) =>{
        console.log(1)
        resolve()
        console.log(2)
    })
    promise.then(()=>{
        console.log(3)
    }) 
    console.log(4)
    

    相关文章

      网友评论

          本文标题:几个习题

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