if (typeof variable !== 'undefined') { // the variable is defined }
var x = (typeof x === 'undefined') ? your_default_value : x;