3 ms·
Why an array with zero element should be false? It doesn't make a lot of sense. And writing if (array.length > 0) is more explicit than writing if (array) anywa
by alerighi 5y ago
Why an array with zero element should be false? It doesn't make a lot of sense. And writing if (array.length > 0) is more explicit than writing if (array) anyway. Even in python, I prefer to be explicit and say if len(array) > 0 than to rely on implicit conversion rules.
- marcosdumay 5y agoPersonally, I don't like if even accepting things that are not boolean. But an empty array being false makes exactly as much sense as an empty string being false, and both should have always the same behavior. If you want objects to behave like dictionaries, an empty object should also behave the same, by the way.
- heavyset_go 5y agoI'd argue that `if empty_list` is already explicit in Python.
- 65 5y agoIt would be better if Javascript had Array.empty() instead of comparing array length. It would make things even more explicit and more convenient.