function typeOf(x) { if (x === null) return 'null'; if (x == null) return 'undefined'; var type = typeof x, c = x.constructor; if (type === 'number') { if (isNaN(x)) return 'NaN'; if (!isFinite(x)) return x === Infinity ? 'Infinity' : '-Infinity'; } if (type === 'object') { return c && c.name ? c.name : Object.prototype.toString.call(x).slice(8, -1); } return type; } console.log(typeOf(undefined))