Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for false

Is there any better way of doing this?

if(borrar() !== false) {     alert('tatatata bum bum bum prapra'); } return false; 
like image 746
Alex Avatar asked Apr 13 '12 11:04

Alex


People also ask

How do you know if a value is false?

Use the strict equality (===) operator to check if a variable is equal to false - myVar === false . The strict equality operator will return true if the variable is equal to false , otherwise it will return false .

How do you check for false in Python?

You can check if a value is either truthy or falsy with the built-in bool() function. According to the Python Documentation, this function: Returns a Boolean value, i.e. one of True or False .

Is Boolean a check?

To check if a value is of boolean type, check if the value is equal to false or equal to true , e.g. if (variable === true || variable === false) . Boolean values can only be true and false , so if either condition is met, the value has a type of boolean. Copied!

Is true or false in JavaScript?

The Javascript standard defines true and false values as a unique data type called a Javascript boolean. Javascript booleans may be true , false , or (in certain contexts) a value that evaluates to either true or false .


1 Answers

If you want to check for false and alert if not, then no there isn't.

If you use if(val), then anything that evaluates to 'truthy', like a non-empty string, will also pass. So it depends on how stringent your criterion is. Using === and !== is generally considered good practice, to avoid accidentally matching truthy or falsy conditions via JavaScript's implicit boolean tests.

like image 134
Phil H Avatar answered Oct 04 '22 18:10

Phil H