How to check for “undefined” in JavaScript? [duplicate]

What is the most appropriate way to test if a variable is undefined in JavaScript? I've seen several possible ways:
if (window.myVariable)
Or
if (typeof(myVariable) != "undefined")
Or
if (myVariable) //This throws an error if undefined. Should this be in Try/Catch?
Javascript
- asked 9 years ago
- B Butts
0Answer

Your Answer