Empty arrays are true but they’re also equal to false.

var arr = [];
console.log('Array:', arr);
if (arr) console.log("It's true!");
if (arr == false) console.log("It's false!");
if (arr && arr == false) console.log("...what??");

I guess this is due to the implicit conversion operated by the equality operator.

Can anyone explain what’s going on behind the scenes?

9 Answers
9

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *