ProAnswers.org

Checking Whether a Variable or Property Is null or undefined?

    var myData = {

      name : "JavaScript",

      city : null

    };

    if (!myData.name) {

      document.writeln("name IS null or undefined");

    } else {

      document.writeln("name is NOT null or undefined");

    }

    if (!myData.city) {

      document.writeln("city IS null or undefined");

    } else {

      document.writeln("city is NOT null or undefined");

    }

  





If a variable or property is null or undefined, the coerced boolean value is false.