Is there any reason to use !!someValue (which is equivalent to Boolean(someValue)) in a boolean context? In other words, in situations like if (someValue) ..., does it make sense to write if (!!someValue) ...?
It hurts my eyes and I think it's redundant, but I want to verify that there aren't any edge cases that require it - because I came across a codebase where this seems to be the default way of checking for truthiness.
Clarification: yes, in the general case !!someValue will convert someValue to a boolean; I'm referring to contexts where the runtime will automatically convert someValue to true or false.
That's a helpful way of converting any data type into boolean; The exact synonym would be:
Some prefer the 'double bang' as being more coincise, while others prefer the classic conversion with
Boolean(someValue)for better readability.So returning to your question, it's most likely redundant in conditions, but it can be handy when needing a conversion from any type to boolean.