Is there any better way of doing this?
if(borrar() !== false) { alert('tatatata bum bum bum prapra'); } return 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 .
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 .
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!
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 .
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.
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