Home › Forums › Back End › Testing for not true vs true › Re: Testing for not true vs true
November 12, 2012 at 1:34 pm
#114050
TheDoc
Member
@fooman, that’s right, it’s a double test.
Let’s say `$somevar = false`. If you do:
if( $somevar === false )
…what you’re really writing is
if( false === false )
So you can just do
if( !$somevar )
You’ll see this a lot in JS where people are checking something:
Another reason you’ll want to use `!` is because it checks for more than just `false`. You may be looking through an array looking for a value and it could return:
- null
- undefined
- empty string
None of those things === false, so you wouldn’t be able to catch them. If you used `!$somevar` then you are golden!