美文网首页
类型判断

类型判断

作者: 回不去的那些时光 | 来源:发表于2020-01-02 21:45 被阅读0次

基本数据类型用typeof

var a = "test";
console.log(typeof(a));     // string

复合类型用instanceof和constructor

var b = new Date();
console.log(b instanceof Date);    // true

console.log(b.constructor === Date);  // true

通用方式 prototype

var a = "test";
var b = new Date();
console.log(Object.prototype.toString.call(a) === '[object String]');  // true
console.log(Object.prototype.toString.call(b) === '[object Date]');  // true

相关文章

  • NodeJs实用技巧

    判断数组类型为 Array 判断对象类型为 Object 判断对象类型为 Number

  • 饿了吗大前端阅读(一)

    类型判断 我记得的类型判断函数就是 typeOf:判断基本类型和Object instanceof:判断是否是指定...

  • JavaScript - 4.数据类型判断

    数据类型判断 节点类型 nodeType 数据类型 typeof 方法 数组 Array 的判断 非数字的判断

  • 类型判断和JSON判断

    类型判断 JSON判断

  • 类型判断

    is as? as! Any 用法: AnyObject

  • 判断类型

    类型 JavaScript 中有七种内置类型: 空值 (null)未定义 (undefined)布尔值 (bool...

  • 类型判断

    typeof操作符 typeof返回一个表示数据类型的字符串,返回结果包括:number、string、boole...

  • 类型判断

  • 类型判断

    js中的类型: 基本数据类型:Undefined、Null、Boolean、Number、String,Symbo...

  • 类型判断

    检查当前元素的类型 (传入的type首字母可以小写)

网友评论

      本文标题:类型判断

      本文链接:https://www.haomeiwen.com/subject/edhaoctx.html