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") {
0

5 Answers 5

6
if (typeof variable == 'undefined')
Sign up to request clarification or add additional context in comments.

Comments

6
if(typeof(variable) == 'undefined')

3 Comments

You don’t need the parentheses as typeof is an operator and not a function.
ya you are right Gumbo... sorry about that :) was in a hurry when i answered :P
1

Use the typeof operator here, like this:

if(typeof variable == "undefined") {

2 Comments

Why would you add an extra call to typeof when simply checking variable == undefined works?
@Justin - undefined may be redefined, for example: jsfiddle.net/nick_craver/gHjg5
0
if(variable == undefined) {

Comments

0

The first one

if (variable == undefined) {}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.