DEV Community

mhsohag11
mhsohag11

Posted on

Answer: How to check a not-defined variable in JavaScript

The only way to truly test if a variable is undefined is to do the following. Remember, undefined is an object in JavaScript.

if (typeof someVar === 'undefined') {
  // Your variable is undefined
}

Some of the other solutions in this thread will lead you to believe a variable…

Top comments (0)