if([]){}//true
All JavaScript objects are truthy - they all coerce to the Boolean value true
.
if([]==true){}//false
If one Operand is an Object, and the other operand is a Boolean, then both operands coerce to a Number value. An empty array will coerce to 0
:
0 == 1 // false
if([1]==true){}//true
Same thing here. For an array with one item, that item will coerce to Number and that value will be compared to the other operand:
1 == 1 // true
if([2]==true){}//false
is:
2 == 1 // false
if([1,2]==true){}//false
If the array has multiple items, the coercion to Number will result in NaN
:
NaN == 1 // false
if(['Hi']==true){}//false
The string coerces to the Number value NaN
:
NaN == 1 // false
if([{aaa:1}]==true){}//false
An object also coerces to the Number value NaN
:
NaN == 1 // false