Raj*_*jat 0 javascript arrays coercion comparison-operators
我知道抽象比较会将 LHS 转换为 StringString([null, undefined, []])并将结果为',,'.
但是String(null)是'null'并且String(undefined)是'undefined'。因此,如何String([null, undefined, []])是',,'?
那是因为。
==定义https://tc39.es/ecma262/#sec-abstract-equality-comparison参见步骤 11:If Type(x) is Object and Type(y) is either String, Number, BigInt, or Symbol, return the result of the comparison ? ToPrimitive(x) == y.ToPrimitive发生:https : //tc39.es/ecma262/#sec-toprimitiveOrdinaryToPrimitive发生:https://tc39.es/ecma262/#sec-ordinarytoprimitive调用Array.prototype.toStringArray.prototype.join(arr)请参阅https://tc39.es/ecma262/#sec-array.prototype.tostringArray.prototype.join就是实现的方式:https : //tc39.es/ecma262/#sec-array.prototype.join,最重要的步骤:Repeat, while k < len,
* If k > 0, set R to the string-concatenation of R and sep.
* Let element be ? Get(O, ! ToString(k)).
* If element is undefined or null, let next be the empty String; otherwise, let next be ? ToString(element).
* Set R to the string-concatenation of R and next.
* Set k to k + 1.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
67 次 |
| 最近记录: |