• support@answerspoint.com

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

1604

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 8 years ago
  • viewed 1604 times
  • active 8 years ago

Best Rated Questions