3 ms·
0 and [] are real and meaningful values that have different meanings than nil/null (in what I assume you're referring to as Python) or (in JavaScript) undefined
by eropple 7y ago
0 and [] are real and meaningful values that have different meanings than nil/null (in what I assume you're referring to as Python) or (in JavaScript) undefined. They should be treated as such.
(That JS coerces the empty string to false is also bad.)
- samhh 7y agoThere is both null and undefined in JavaScript. Additionally, an empty array coerces to true because it's an object and objects are always truthy. Personally I'd prefer that not even null/undefined coerced to false, or could otherwise be used in a boolean comparison, as for me they still signify different meanings and even in type-safe languages can lead to subtle bugs. I really dislike coercion having principally worked with JavaScript/TypeScript.