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,206
  • 16
  • 61
  • 93

5 Answers5

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

Use the typeof operator here, like this:

if(typeof variable == "undefined") {
Nick Craver
  • 610,884
  • 134
  • 1,288
  • 1,151
0
if(variable == undefined) {
NicolasT
  • 192
  • 4
0

The first one

if (variable == undefined) {}
Jemes
  • 2,722
  • 19
  • 21