2

I am wondering how to check against an empty variable, here is a code snippet:

    var test = {};

    if (test === null){
        console.log("TRUE!");
    }        
    else{
        console.log("False :(");
    }
    if (test === undefined){
        console.log("TRUE!");
    }
    else{
        console.log("False :(");
    }

Result is False for both conditions, how can I compare against an non-initialized/empty variable?

Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225
Erik Ware
  • 31
  • 5
  • 3
    `Object.getOwnPropertyNames(test).length`. Note that `test` in your code is not empty, it contains a reference to an empty object. – Teemu Jan 20 '17 at 21:42

0 Answers0