use typeof(x) === 'undefined' instead of x === undefined