Examples:
// Numberstypeof 37 === 'number';typeof 3.14 === 'number';typeof(42) === 'number';typeof Math.LN2 === 'number';typeof Infinity === 'number';typeof NaN === 'number'; // Despite being "Not-A-Number"typeof Number(1) === 'number'; // but never use this form!复制代码
// Stringstypeof "" === 'string';typeof "bla" === 'string';typeof (typeof 1) === 'string'; // typeof always returns a stringtypeof String("abc") === 'string'; // but never use this form!复制代码
// Booleanstypeof true === 'boolean';typeof false === 'boolean';typeof Boolean(true) === 'boolean'; // but never use this form!复制代码
// Symbolstypeof Symbol() === 'symbol'typeof Symbol('foo') === 'symbol'typeof Symbol.iterator === 'symbol'复制代码
// Undefinedtypeof undefined === 'undefined';typeof declaredButUndefinedVariable === 'undefined';typeof undeclaredVariable === 'undefined'; 复制代码
// Objectstypeof {a:1} === 'object';// use Array.isArray or Object.prototype.toString.call// to differentiate regular objects from arraystypeof [1, 2, 4] === 'object';typeof new Date() === 'object';// The following is confusing. Don't use!typeof new Boolean(true) === 'object'; typeof new Number(1) === 'object'; typeof new String("abc") === 'object';复制代码
// Functionstypeof function(){} === 'function';typeof class C {} === 'function';typeof Math.sin === 'function';// This stands since the beginning of JavaScripttypeof null === 'object';复制代码