diff --git a/README.md b/README.md index 6a551e8..ccd5d4d 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ smart people at [Hashrocket](http://hashrocket.com/). ## javascript - [Character Codes from Keyboard Listeners](javascript/character-codes-from-keyboard-listeners.md) +- [Truthiness of Integer Arrays](javascript/truthiness-of-integer-arrays.md) ### postgres diff --git a/javascript/truthiness-of-integer-arrays.md b/javascript/truthiness-of-integer-arrays.md new file mode 100644 index 0000000..9e66737 --- /dev/null +++ b/javascript/truthiness-of-integer-arrays.md @@ -0,0 +1,28 @@ +# Truthiness of Integer Arrays + +We can consider the truthiness of `[1]` as follows: + +```javascript +> [1] == true +=> true +> Boolean(true) +=> true +> Boolean([1]) +=> true +``` + +We can consider the truthiness of `[0]` as follows: + +```javascript +> [0] == false +=> true +> Boolean(false) +=> false +> Boolean([0]) +=> true +``` + +The truthiness of `[0]` does not seem to be consistent. + +See this [JavaScript Equality Table](https://dorey.github.io/JavaScript-Equality-Table/) +for more details.