Проверка, если VAR не определен JS

if(typeof x !== 'undefined'){
  alert("Variable x is defined.");
}