javascript if number is undefined set to 0 code example Example: javascript set variable if not defined var x = (typeof x === 'undefined') ? your_default_value : x;