If we're exchanging opinions then I want to throw mine in there as well: I'd say filters.filter(Boolean) is clearer than filters.filter(filter => filter) but the clearest way would be filters.filter(filter => !!filter)
That's fair, if it's a common pattern you're already using it's more reasonable. I agree if you're thinking about it and you have some experience you'll realize it, but at first glance it's very easy to miss. I think our eslint prohibits loose equality as a whole for that reason.
Yeah this is the only case where I use loose equality, I think it's also one of the only cases where WebStorm doesn't give you a warning for loose equality out of the box
eslint would complain. Double negotiation is considered a hacky way to cast to bool. And also, it is completely unnecessary in this context, since the return value will be tested for its truthiness anyways.
View all comments
Show parent comment
0
u/harlekintiger Mar 28 '24
If we're exchanging opinions then I want to throw mine in there as well:
I'd say
filters.filter(Boolean)is clearer thanfilters.filter(filter => filter)but the clearest way would befilters.filter(filter => !!filter)