我认为结果是合理的。我唯一不确定的是+[]
,但我可能已经弄清楚了。就像你说的,松散的比较可能会产生误导,但对我来说是有道理的。
console.log([] && true); //true - there is an array
console.log([] == false); //true, the array is empty
console.log(![]); //false, there is an array
console.log(!![]); //true, there isn't not an array
console.log(![] == []); //true, no array is loosely like an empty array
console.log(+[]); //0, I think this converts the array to a number, 0 being the logical choice. +[1] will return "1" and +[1,2] is "NaN" - which seems to be because the conversion is no longer feasible.
console.log([].toString()); //string '', as expected - also see next example
console.log(['stuff',{}].toString()); //stuff,[object Object]