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

来源:互联网 发布:手机u盘数据恢复 编辑:程序博客网 时间:2024/05/18 01:07

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]
阅读全文
0 0
原创粉丝点击