3

Possible Duplicate:
Detecting an undefined object property in JavaScript

Would it be like this?

if(variable == undefined) {

or would it be like this?

if(variable == "undefined") {
Community
  • 1
  • 1
chromedude
  • 4,246
  • 16
  • 65
  • 96

5 Answers5

6
if(typeof(variable) == 'undefined')
Atul Dravid
  • 1,055
  • 3
  • 14
  • 30
6
if (typeof variable == 'undefined')
1

Use the typeof operator here, like this:

if(typeof variable == "undefined") {
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
0
if(variable == undefined) {
NicolasT
  • 192
  • 4
0

The first one

if (variable == undefined) {}
Jemes
  • 2,822
  • 21
  • 22