sprawdzanie, czy var nie jest zdefiniowany JS

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