typeof,instanceof,Object.prototype.toString.call(),js内置对象

javascript有哪些内置对象

  • Number 数值对象
  • String 字符串对象
  • Boolean 布尔对象
  • RegExp 正则对象
  • Date 日期对象
  • Object 基础对象
  • Function 函数构造器
  • Arguments 函数参数对象
  • Math 数学对象
  • Error 异常对象
  • Array 数组对象

Javascript有三种方法,可以确定一个值到底是什么类型

  • typeof运算符—返回类型:

    • number
    • string
    • boolean
    • undefined
    • function
    • object
    • symbol(es6新增类型)
  • instanceof运算符—返回类型:

    • true
    • false
  • Object.prototype.toString.call()方法—返回类型:

    • [object Number]
    • [object String]
    • [object Boolean]
    • [object Undefined]
    • [object Function]
    • [object Object]
    • [object Array]
    • [object Arguments]
    • [object Math]
    • [object Symbol]

`

    //typeof运算符---返回类型:
    typeof 123 //number
    typeof '123' //string
    typeof false //boolean
    typeof undefined // undefined
    typeof function f(){}//function
    typeof null //object
    typeof Symbol()//symbol
    typeof Symbol//function

    //instanceof运算符---返回类型:
    Number instanceof Number//false
    String instanceof object//true

    //Object.prototype.toString.call()方法---返回类型:
    Object.prototype.toString.call(123) //[object Number]
    Object.prototype.toString.call('123') //[object String]
    Object.prototype.toString.call(true) //[object Boolean]
    Object.prototype.toString.call(undefined) //[object Undefined]
    Object.prototype.toString.call(function(){}) //[object Function]
    Object.prototype.toString.call({}) //[object Object]
    Object.prototype.toString.call([]) //[object Array]
    (function(){console.log(Object.prototype.toString.call(arguments))})()//[object Arguments]
     Object.prototype.toString.call(Math) //[object Math]
     Object.prototype.toString.call(Symbol())//[object Symbol]
     Object.prototype.toString.call(null)//[object Null]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值