问题描述
我知道,我知道,我知道我的这个故事,在我完全理解关闭之前,有几个问题,但JavaScript中的很多奇怪的行为并不是我想到的...
那么哪个陷阱应该你肯定会指出新秀?
。
''=='0' // false
0 ==''// true
0 =='0'// true
false =='false'// false
false =='0 '// true
false == undefined // false
false == null // false
null == undefined // true
\t\r\ n= = 0 // true
以及 I'm planing on giving an introduction talk on JavaScript and in the preparation process I wondered what the top pitfalls are that rookies fall into. I know I've had a few gotchas before I fully understood closure, but much of the strange behavior in JavaScript is not something I think about any more... So, which pitfalls should you definitely point out to the rookies? As well as the difference between 这篇关于什么是顶级的JavaScript陷阱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! null $之间的区别c $ c>和
未定义
。如上表所列,比较 null
& 未定义
与 ==
返回true,但使用 ===
它返回false。一旦您明白 undefined
与具有 null
值的变量有很大的不同,那么这个行为是有道理的, '' == '0' //false
0 == '' //true
0 == '0' //true
false == 'false' //false
false == '0' //true
false == undefined //false
false == null //false
null == undefined //true
" \t\r\n" == 0 //true
null
and undefined
. As listed in the table above, comparing null
& undefined
with ==
returns true, but with ===
it returns false. This behavior makes sense once you understand that undefined
is very different from a variable having a null
value, and something holding the value undefined
is different from something being undefined.