我不明白为什么下面代码的输出将NaN分隔到数组的开头,而将undefined值分隔到数组的末尾。我正将NaN和undefined强制到0,所以我希望它们能够同时(分组)在一起。[9, undefined, NaN, undefined].sort( // coercing NaN or undefined to 0
const} else if (first
在其他类型化语言中,我对TypeScripts或标准类型以外的任何东西都比较陌生,我正试图找到一种很好的方法来键入这个函数。我想去掉参数的任意类型和返回类型。函数返回非空、未定义或NaN的第一个值。== NaN } return null;这就是你使用它的方式:
test('coalesce returns the first value that is not null, undefined
最近,当我发现Number(undefined)等于NaN</code>, but if you do数字(未定义的) === NaNyou getfalse`‘时,我考虑定义一个函数来从无聊中复制NaN我甚至尝试了(typeof Number(undefined)) === (typeof NaN),它返回true。
JavaScript在这里做什么?