JavaScript's Loose Equality Causes Empty Array to Equal False
A JavaScript quirk causes the expression '[] == false' to evaluate as true. This occurs because the language's loose equality operator performs type conversion. During comparison, false is converted to 0, and the empty array is converted to an empty string, which then becomes 0. The strict equality operator '===' avoids this by checking both value and type without conversion.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in