I've recently started using double exclamation points !!
before an object to make sure that it's not null and that it's not undefined and not an empty string, to make sure that I encompass all the different ways that a variable can be empty.
Is this necessary? It's hard to read, for instance:
if(!!name)
vs if(name)
Any opinions on this? I want my code to be safe and not get into conditions where a null pointer exception and other things can occur, but I also want my code to be readable.
What you're doing is already done by JavaScript natively.
if( value ) {
}
will evaluate to true as long as value
is not:
Check out the toboolean conversions in the specification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With