Alexey
Alexey

Reputation: 414

How to fail gracefully in IE instead of seeing SCRIPT5009 if a variable is undefined?

if (!variable) ui.notify('functionality not available due to...');

When doing this simple check in IE we get SCRIPT5009: 'variable' is undefined, where it is exactly what we are trying to check but not fail so disgracefully. How to make this graceful fail come true?

Upvotes: 0

Views: 603

Answers (2)

Andrew D.
Andrew D.

Reputation: 8230

Next code can help you:

if (typeof variable === "undefined") console.log("undefined");
else console.log("defined"); 

Upvotes: 3

epoch
epoch

Reputation: 16605

You can try:

if (!window['variable']) ui.notify('functionality not available due to...');

assuming that variable is global

Upvotes: 1

Related Questions