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. excel VBA一个fuction同时执行多个正则表达式,实现方法

    代码: Function zhengze3(ze1 As String, ze2 As String, Rng1 As Range, Rng2 As Range)    Set regx1 = Cre ...

  2. Docker与k8s的恩怨情仇(四)-云原生时代的闭源落幕

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 在本系列前几篇文章中,我们介绍了从Cloud Foundry到Docker等PaaS平台的发展迭代过程.今天 ...

  3. Redis 实战篇:GEO助我邂逅附近女神

    码老湿,阅读了你的巧用数据类型实现亿级数据统计之后,我学会了如何游刃有余的使用不同的数据类型(String.Hash.List.Set.Sorted Set.HyperLogLog.Bitmap)去解 ...

  4. IntelliJ idea -- 在WEB-INF下创建两个文件夹:classes 和 lib

    1.首先在WEB-INF下面创建两个文件夹 classes  和 lib 2.文件 --> 项目结构 3.选择路径 4.选择依赖项 5.选择刚创建好的lib文件夹,然后确定 6.选择 Jar D ...

  5. Linux之 du的用法

    du 显示目录和文件的大小,常用命令为 du -sh * du -sm * | sort -n //统计当前目录大小 并按大小 排序 du 无参数 显示当前路径下的目录大小和子目录大小 -b/-k/- ...

  6. XCTF 进阶区 CAT

    这题脑洞是真的大,讲道理 看到这个,先尝试了一下命令拼接,发现字符被过滤了应该.fuzz一下看看,有哪些字符还没被过滤了 import requests dictory=["!", ...

  7. XCTF_MFC逆向

    讲道理这题有点脑洞,也可能我太菜了,首先对mfc就不太熟悉,不知道是个啥玩意,只能边看大佬的wp百度边做了,之后要恶补一下mfc的知识了. 题目一开始说flag在控件中,看到大佬都是用Mfcspy来找 ...

  8. C语言:fopen

    fopen,传递文件名参数,w+选项读取用fread或fgets,其中fread是按字节读取,fgets每次读取一个字符串写入用fwrite或fputs或fprintf,fwrite按字节写入,fpu ...

  9. EditPlus运行java时如何从键盘输入数据

    在练习Java的Scanner时,EditPlus如何读取从键盘输入的数呢? 例如如下程序,编译通过,运行时却输入不了数据: 1 package myP101; 2 3 import java.uti ...

  10. 程序员们,还在挣扎着上不了github吗

    前言 无兄弟,不篮球:无github,不代码.github和stackoverflow是程序员们的最爱,哪怕是github总是在抽疯,虐了程序员们千百遍,但他们还是想各种办法艰难地在github分享他 ...