码迷,mamicode.com
首页 > 其他好文 > 详细

标准对象

时间:2020-02-05 09:27:46      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:define   efi   com   figure   highlight   其他   object   种类型   ble   

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

标准对象

标签:define   efi   com   figure   highlight   其他   object   种类型   ble   

原文地址:https://www.cnblogs.com/lijianming180/p/12262453.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!