Check if variable is false and not either true or undefined

If the variable is declared then:

if (myvar === false) {

will work fine. === won’t consider false to be undefined.

If it is undefined and undeclared then you should check its type before trying to use it (otherwise you will get a reference error).

if(typeof myvar === 'boolean' && myvar === false) {

That said, you should ensure that the variable is always declared if you plan to try to use it.

var myvar;
// ...
// some code that may or may not assign a value to myvar
// ...
if (myvar === false) {

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)