四种判断JS数据类型方法.docVIP

  • 2
  • 0
  • 约3.51千字
  • 约 7页
  • 2017-07-04 发布于湖北
  • 举报
四种判断JS数据类型的方法 说到数据类型,我们先说一下JavaScript?中常见的几种数据类型: 基本类型:string,number,boolean 特殊类型:undefined,null 引用类型:Object,Function,Function,Array,RegExp,Date,... 很多时候我们都需要通过判断变量的数据类型来进行下一步操作,下面我们介绍常用的4种方法: 1、typeof typeof 返回一个表示数据类型的字符串,返回结果包括:number、boolean、string、object、undefined、function等6种数据类型。 typeof ; // string 有效 typeof 1; // number 有效 typeof true; //boolean 有效 typeof undefined; //undefined 有效 typeof null; //object 无效 typeof [] ; //object 无效 typeof new Function(); // function 有效 typeof new Date(); //object 无效 typeof new RegExp(); //object 无效 typeof 可以对JS基础数据类型做出准确的判断,而对于引用类型返回的基本上都是object, 其实返回objec

文档评论(0)

1亿VIP精品文档

相关文档