给出以下代码:
if ("string") {
console.log('true!');
}
//logs "true" to the console
if ("string"==true) {
console.log('true!');
}
//doesn't log anything
为什么会这样?我以为"string"布尔值会被强制转换为数字。因此true变得1和"string"变NaN。第二条if语句很有意义,但是我不明白为什么第一条语句会导致内部循环被求值。这里发生了什么?
慕婉清6462132
qq_笑_17
随时随地看视频慕课网APP
相关分类