首页 > 其他 > 详细

标准对象

时间:2020-02-05 11:12:02      阅读:63      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!