0

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

sehummel
  • 5,476
  • 24
  • 90
  • 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,659
  • 3
  • 55
  • 71
0
if(typeof variable === "undefined") {
    //code here
}
Shurdoof
  • 1,719
  • 13
  • 16