Rouge
Rouge

Reputation: 4239

weird variable issue is IE

I am having a weird issue in IE.

I have

The tool variable can be empty and it seems like that I need to have tool=='' to make IE happy.

//work in IE and other browsers..
  if(tool==null || tool==''){Alert('bang!!!');}

//doesn't work in IE but not other browsers.
  if(tool==null){Alert('bang!!!');}

What's going on here?

Upvotes: 0

Views: 43

Answers (2)

Giona
Giona

Reputation: 21114

This article: http://saladwithsteve.com/2008/02/javascript-undefined-vs-null.html explains it very well.

You can use if(!tool) alert('bang');

Upvotes: 0

thecodeparadox
thecodeparadox

Reputation: 87073

Try this:

if( !tool ){
  Alert('bang!!!');
}

Here, !tool will return true if tool = null or tool = ''.

Upvotes: 1

Related Questions