Today I Learned

hashrocket A Hashrocket project

Truthiness of Integer Arrays

We can consider the truthiness of [1] as follows:

> [1] == true
=> true
> Boolean(true)
=> true
> Boolean([1])
=> true

We can consider the truthiness of [0] as follows:

> [0] == false
=> true
> Boolean(false)
=> false
> Boolean([0])
=> true

The truthiness of [0] does not seem to be consistent.

See this JavaScript Equality Table for more details.

See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.