Verificar si VAR no está definido JS
if(typeof x !== 'undefined'){
alert("Variable x is defined.");
}
if(typeof x !== 'undefined'){
alert("Variable x is defined.");
}
var x = (typeof x === 'undefined') ? your_default_value : x;