0

How do I check if a given variable has a value? What is the JS equivalent of PHP's isset?

sehummel
  • 5,276
  • 23
  • 86
  • 137

2 Answers2

1
if (myVariable === undefined) {
    // myVariable has not been assigned a value...
}

Also, this same question was asked and answered here on Stackoverflow. See, How can I determine if a JavaScript variable is defined in a page?

Community
  • 1
  • 1
Scott Mitchell
  • 8,569
  • 3
  • 52
  • 71
0
if(typeof variable === "undefined") {
    //code here
}
Shurdoof
  • 1,669
  • 14
  • 16