typeof获取对象的的类型
1 2 3 4 5 6 7 8 9
| typeof 123; // 'number' typeof NaN; // 'number' typeof 'str'; // 'string' typeof true; // 'boolean' typeof undefined; // 'undefined' typeof Math.abs; // 'function' typeof null; // 'object' typeof []; // 'object' typeof {}; // 'object'
| 大专栏 标准对象
各种类型的判断方法
- typeof操作符可以判断出number、boolean、string、function和undefined;
- 判断Array要使用Array.isArray(arr);
- 判断null请使用myVar === null;
- 判断某个全局变量是否存在用typeof window.myVar === ‘undefined’;
- 函数内部判断某个变量是否存在用typeof myVar === ‘undefined’;
除了null和undefined,其他的object都有toString方法;
对于数值类型调用toString方法需要用括号或双引号括起:
1 2
| 123..toString(); // '123', 注意是两个点! (123).toString(); // '123'
|
Date
标准对象
原文:https://www.cnblogs.com/lijianming180/p/12262453.html