1. typeof用在基本数据类型和函数时,返回其对应类型的描述,对于引用类型都返回为object.
  2. instanceof无法判断基本数据类型,对于引用类型数据,返回其其对应类型。
  3. Object.prototype.toString无论基本数据类型还是引用类型返回其对应类型。

对应测试结果如下:

  typeof test instanceof Object.prototype.toString.call(test)
var test = 'xuriliang'; string test instanceof String //false [object String]
var test = 27; number test instanceof Number //false [object Number]
var test = true; boolean test instanceof Boolean //false [object Boolean]
var test = [1,2,3]; object test instanceof Array //true [object Array]
    test instanceof Object //true  
var test = null; object test instanceof Object //false [object Null]
var test = undefined; undefined test instanceof Object //false [object Undefined]
var test = new String('xuriliang') object test instanceof String //true [object String]
    test instanceof Object //true  
var test = new Number(27) object test instanceof Number //true [object Number]
    test instanceof Object //true  
var test = new Boolean(true) object test instanceof Boolean //true [object Boolean]
    test instanceof Object //true  
var test = new Array(1,2,3) object test instanceof Array //true [object Array]
    test instanceof Object //true  
var test = function(){} function test instanceof Function //true [object Function]
    test instanceof Object //true  
var test = /d/ object test instanceof RegExp //true [object RegExp]
    test instanceof Object //true

JS基础-数据类型判断typeof、instanceof、Object.prototype.toString的更多相关文章

  1. 类型判断----小白讲解typeof,instanceof,Object.prototype.toString.call()

    1.typeof只能判断基本类型数据, 例子: typeof 1 // "number" typeof '1' // "string" typeof true ...

  2. js变量类型判断 严格通用 Object.prototype.toString.call()

    Object.prototype.toString.call()判断结果: Object.prototype.toString.call(true) "[object Boolean]&qu ...

  3. typeof()与Object.prototype.toString.call()

    用typeof方法只能初步判断number string undefined boolean object function symbol这几种初步类型 使用Object.prototype.toSt ...

  4. typeof 和 Object.prototype.toString.call 数据类型判断的区别

    使用 typeof 来判断数据类型,只能区分基本类型,即 “number”,”string”,”undefined”,”boolean”,”object” 五种. 但 Object.prototype ...

  5. typeof 、Object.prototype.toString和 instanceof

    数据类型 js 基本类型包括:Undefined  symbol null string boolean number js 引用类型包括:object array Date RegExp typeo ...

  6. typeof操作符,返回数据类型Array.isArray()、Object.prototype.toString.call()

    源地址https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/typeof typeof操作符 // N ...

  7. 深入剖析JavaScript中的数据类型判断(typeof instanceof prototype.constructor)

    关于JavaScript中的类型判断,我想大部分JavaScripter 都很清楚 typeof 和  instanceof,却很少有人知道 constructor,以及constructor与前面二 ...

  8. 使用Object.prototype.toString.call()方法精确判断对象的类型

    在JavaScript里使用typeof判断数据类型,只能区分基本类型,即:number.string.undefined.boolean.object. 对于null.array.function. ...

  9. JavaScript instanceof深度剖析以及Object.prototype.toString.call()使用

    本文由segementfalt上的一道instanceof题引出: var str = new String("hello world"); console.log(str ins ...

随机推荐

  1. centos8添加中文语言包

    centos8添加中文语言包 系统:centos8 查看: [root@centos8]# locale -a 不支持中文包,按照centos7的方式安装:yum install kde-l10n-C ...

  2. hdu 1116 敌兵布阵 线段树 区间求和 单点更新

    线段树的基本知识可以先google一下,不是很难理解 线段树功能:update:单点增减 query:区间求和 #include <bits/stdc++.h> #define lson ...

  3. hdu 2604 递推 矩阵快速幂

    HDU 2604 Queuing (递推+矩阵快速幂) 这位作者讲的不错,可以看看他的 #include <cstdio> #include <iostream> #inclu ...

  4. 暑假自学java第六天

    1,方法的覆盖:当子类继承父类,而子类中的方法与父类中方法的名称,返回类型及参数都完全一致时,就称子类中的方法覆盖了父类中的方法,有时也称方法的"重写" [不需要关键字] 2,th ...

  5. 9 shell 退出状态

    退出状态和逻辑运算符的组合 Shell 逻辑运算符 举栗 命令的退出状态(exit statu)是指执行完Linux命令或shell函数后,该命令或函数返回给调用它的程序的一个比较小的整数值.if 语 ...

  6. 计算机网络体系结构整理-第二单元IP技术

    IP技术 1.IPV4 Ipv4的报头格式 Ipv4地址分为ABCDE类, 类别 IP地址范围 私有IP地址范围 A 0.0.0.0-127.255.255.255 10.0.0.0-10.255.2 ...

  7. Python----MongoDB数据库

    什么是MongoDB ? MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统. 在高负载的情况下,添加更多的节点,可以保证服务器性能. MongoDB 旨在为WEB应用提供 ...

  8. web自动化之浏览器启动

    一.环境准备 1.本地引入jar 从http://selenium-release.storage.googleapis.com/index.html?path=3.9/,下载selenium-ser ...

  9. SpringBoot通过Ajax批量将excel中数据导入数据库

    Spring Boot通过Ajax上传Excel并将数据批量读取到数据库中 适合场景:需要通过excel表格批量向数据库中导入信息 操作流程 [1]前端上传一个excel表格 [2] 后端接收这个ex ...

  10. JavaScript学习笔记:你必须要懂的原生JS(一)

    1.原始类型有哪几种?null是对象吗?原始数据类型和复杂数据类型存储有什么区别? 原始类型有6种,分别是undefined,null,bool,string,number,symbol(ES6新增) ...