Archive for the 'JavaScript' Category

Check if a variable exists in JavaScript

Posted by admin No Commented May 2 2009

Under: JavaScript

At times, you might want to check if a variable exists. Here’s how you can do it:

if (typeof VariableName != ‘undefined’)

where, of course, VariableName is the actual name of your variable.
But what if you know for sure that your variable exists, but you don’t know if it stores a value?
This little Javascript snippet can help:

if [...]