一个变量与自身比较

一个变量与自身比较

本文介绍了一个变量与自身比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绊了这种填充工具Array.prototype.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 是的 - 的的不是 === 本身。 包括应该使用的,这是从的的(使用 === )或的(中的 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).

这篇关于一个变量与自身比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:18