Checking for undefined variables in Javascript
In Javascript if you want to check to see if a variable is defined or not you need to make use of the typeof operator for this check. This will return a string that you can then check to see if it is undefined. For example, here's how to check if the variable named someVariable is defined or not...
if ( typeof(someVariable) == 'undefined' ) {
// someVariable is *not* defined
...
} else {
// someVariable is defined
...
}
| Rating: | 100% positive, 1 Vote |
| Categories: | Javascript web programming |
| Added: | on Jan 14, 2009 at 9:47 am |
| Added By: | an anonymous user |
| Searches: | javascript web check variable programming |

