checking if var is not defined js

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

Also in JavaScript: