JavaScript的typeOf

typeOf查看字符串类型

typeof undefined
"undefined"

typeof null
"object"

typeof {}
"object"

typeof []
"object"

typeof function(){}
"function"

typeof "aa"
"string"

typeof 11
"number"

typeof true
"boolean

需要注意的:

typeof Infinity === 'number';
typeof NaN === 'number';
typeof (typeof 1) === 'string';
typeof [1, 2, 4] === 'object';
typeof Math.sin === 'function';
typeof Number(1) === 'number'; 

typeof Symbol() === 'symbol';
typeof Symbol('foo') === 'symbol';
typeof Symbol.iterator === 'symbol';

typeof new Boolean(true) === 'object';
typeof new Number(1) === 'object';
typeof new String("abc") === 'object';

typeof new Function() === 'function';

猜你喜欢

转载自blog.csdn.net/zyz00000000/article/details/106281369
今日推荐