一位 friend 说我应该使用! (obj == null)
,因为它比 obj != null
更好,但他不记得为什么要这样做。
使用有什么理由吗? (obj == null)
?
有什么区别吗?我的意思是,当 obj
不 null
且都不 undefined
时,两者都应该返回 true
,这是否正确? (我有点困惑)
当答案都是相同的时候,我想知道,这对所有 JavaScript 版本都是正确的吗? (我的意思是,两者都适用于所有浏览器吗?)
最佳答案
Is there any reason for using ! (obj == null)?
有些人可能会发现它更容易(或更难)阅读。
is there any change, I mean, both should return true when the obj is not null and neither undefined, is that right or not? (I am a little confused)
没有。它们的意思完全一样。
And when the answer is both result to the same, then I would like to know, is that right for all java-script versions? (I mean, both work on all browsers or not?)
是的。
关于javascript - "obj != null"与 "! (obj == null)"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55933244/