javascript set variable if not defined

JavaScript
var x = (typeof x === 'undefined') ? your_default_value : x;
Source

Also in JavaScript: