# 实现SameValueZero规范的字符比较

function eq(value, other) {
  return value === other || (value !== value && other !== other);
  // 下面代码效果等同上面
  // return value === other || (Number.isNaN(value) && Number.isNaN(other));
}

处理NaN!==NaN的情况,利用JS中只有NaN不等于自己的特征,实现SameValueZero规范的比较。

最近更新时间: 2020/9/6 11:30:38