一个变量与自身比较 [英] Comparing a variable with itself
问题描述
我绊了这种填充工具Array.prototype.includes的。
<一href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes\">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes.
是否有变量与自己对线21,22比较的原因是什么?
如果(searchElement === currentElement ||
(searchElement == searchElement和放大器;!&安培;!currentElement == currentElement)){
返回true;
}
是,这第二个操作数的 ||
并检查是否既 searchElement
和 currentElement
是的 NaN的
- 的的仅在JavaScript值不是 ===
本身。 包括
应该使用的的 SameValueZero
的等价算法,这是从的的 全等比较算法的(使用<一个href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Identity\"相对=nofollow> ===
)或的 EM> SameValue
的算法(中的 Object.is
)。
I stumbled over this polyfill of Array.prototype.includes. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes. Is there a reason for the comparison of the variables with themselves on line 21,22?
if (searchElement === currentElement ||
(searchElement !== searchElement && currentElement !== currentElement)) {
return true;
}
Yes, this second operand of the ||
does check whether both searchElement
and currentElement
are NaN
- the only value in JavaScript that is not ===
to itself. includes
is supposed to use the SameValueZero
equivalence algorithm, which is different from the the Strict Equality Comparison Algorithm (used by ===
) or the SameValue
algorithm (used in Object.is
).
这篇关于一个变量与自身比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!