• support@answerspoint.com

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

1681

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?

0Answer


Your Answer

    Facebook Share        
       
  • asked 9 years ago
  • viewed 1681 times
  • active 9 years ago

Best Rated Questions