几个习题

2020-04-02  本文已影响0人  ads
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)
上一篇下一篇

猜你喜欢

热点阅读