I wanted to check whether the variable is defined or not. For example, the following throws a not-defined error
alert( x );
How can I cat
I often use the simplest way:
var variable; if (variable === undefined){ console.log('Variable is undefined'); } else { console.log('Variable is defined'); }
EDIT:
Without initializing the variable, exception will be thrown "Uncaught ReferenceError: variable is not defined..."