js踩坑记录

91 阅读1分钟

1、空数组不可以作为if判断条件

if([]){
    console.log('123') 
}
// '123'

原因: if语句的条件表达式,js会自动调用Boolean()将条件表达式转换为布尔值即:

Boolean([]) //true