打印输出
console.log(typeof NULL == typeof undefined)
console.log(typeof null)
console.log(typeof undefined)
console.log(typeof NUll)
结果:
true
object
undefined
undefined
打印输出
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1)
}
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1)
}
结果:
3
3
3
0
1
2
打印输出
const shape = {
radius: 10,
diameter() {
return this.radius * 2
},
perimeter: () => 2 * Math.PI * this.radius
}
shape.diameter()
shape.perimeter()
结果:
20
NaN
输出是20和NaN,因为diameter中的this指的是shape中的radius,但是perimeter由于是箭头函数所以,当我们调用 perimeter 时,this 不是指向 shape 对象,而是它的周围作用域(在例子中是 window)。