javascript - "obj != null"与 "! (obj == null)"?

标签 javascript performance comparison

一位 friend 说我应该使用! (obj == null),因为它比 obj != null 更好,但他不记得为什么要这样做。

使用有什么理由吗? (obj == null)

有什么区别吗?我的意思是,当 objnull 且都不 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/

相关文章:

javascript - 使用 firebase 并使用动态键名保存

javascript - 访问网格数据存储的加载函数内的 sortInfo 属性

javascript - 使用可排序表时出现 d3.v3 错误?

Javascript 性能 - 使用 $.getScript() 添加脚本

python - 使用 Pandas 扩展时间序列事件

java - 判断哪个版本性能更好的最简单直接的方法是什么?

javascript - 如何更改 Fabric.js 对象的值?

php - 使用 PHP 从三个 MySQL 表构建 CSV 表的有效方法

arrays - 检查变量是否以 bash 中的另一个变量开头

c - 来自 int 的基本 C 强制转换警告指针