[英]What is the difference between != and !== operators in JavaScript?
What is the difference between the !==
operator and the !=
operator in JavaScript? JavaScript 中的
!==
运算符和!=
运算符有什么区别? Does it behave similarly to the ===
operator where it compares both value and type?它的行为是否与比较值和类型的
===
运算符相似?
Yes, it's the same operator like ===
, just for in equality:是的,这是相同的运营商像
===
,只是在平等的:
!==
- returns true if the two operands are not identical.!==
- 如果两个操作数不相同,则返回 true。 This operator will not convert the operands types, and only returns false if they are the same type and value.此运算符不会转换操作数类型,并且仅在它们的类型和值相同时返回 false。 — Wikibooks
— 维基教科书
Yes, !==
is the strict version of the !=
operator, no type coercion is done if the operands are of different type:是的,
!==
是!=
运算符的严格版本,如果操作数的类型不同,则不会进行类型强制:
0 != '' // false, type coercion made
0 != '0' // false
false != '0' // false
0 !== '' // true, no type coercion
0 !== '0' // true
false !== '0' // true
I was about to post this w3schools page , but funnily enough it didn't contain this operator!我正要发布这个 w3schools 页面,但有趣的是它没有包含这个操作符!
At least, the !==
is indeed the inverse of ===
which tests the equality of both type and value.至少,
!==
确实是===
的倒数,它测试类型和值的相等性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.