为何[]是false而 !![] 是true

原文连接: 连接描述html

总结一下:post

hint:至关于default,是对象的默认值。code

OrdinaryToPrimitive(input,hint)中,若hint是string,则先toStringvalueOf;其余状况,则先valueOftoStringhtm

因此对于[]来讲,是先valueOftoString,获得的结果是"",因此[]==false是true。对象

而对于!![]来讲,根据规范至关于!!(toBoolean([])),而toBoolean([])为true,因此!![]是true。get

下面看一些例子哦~~input

[1] + [2] - [3] === 9;  // true ,至关于“12” - 3 ,先toString,而后'-'会调用toNumber

[1] + [2] === "12";  // true

[1] +- [2] === "1-2";  // true,这要使用到Symbol.toPrimitive,这儿我本身还没太搞明白,后续再补上

1 - [2] === -1; // true
相关文章
相关标签/搜索