typeof和instanceof的用法
2015-11-13 22:01
302 查看
typeof是一个一元运算,返回值有六种可能: "number," "string," "boolean," "object," "function," 和 "undefined."
instanceof 判断一个变量是否为某个对象的实例。
> typeof null
'object'
> null instanceof Object
'false'
> typeof true
'boolean'
> typeof 123
'number'
> typeof "abc"
'string'
> typeof function() {}
'function'
> typeof {}
'object'
> typeof []
'object'
> typeof Date
'function'
> typeof new Date()
'object'
instanceof 判断一个变量是否为某个对象的实例。
> typeof null
'object'
> null instanceof Object
'false'
> typeof true
'boolean'
> typeof 123
'number'
> typeof "abc"
'string'
> typeof function() {}
'function'
> typeof {}
'object'
> typeof []
'object'
> typeof Date
'function'
> typeof new Date()
'object'
相关文章推荐
- 【转】旋转门算法
- (算法)AA制
- Java 8 新特性终极指南
- Java 8 新特性终极指南
- Android Studio断点调试图文详解(超简单,一看就会)
- android面试攻略(4)
- 第二十一章 授予身份及切换身份
- 第二十二章 集成验证码
- Java 8 新特性终极指南
- 课后作业
- eclipse连hadoop2.x运行wordcount 转载
- C++11新特性
- CentOS 7.1 linux 裁剪 嵌入式 系统 定制
- 第二十章 无状态Web应用集成
- 几种防止过拟合的方法介绍
- [leetcode 19] Remove Nth Node From End of List
- 硬盘分区重新调整后,双系统不能进入Ubuntu14.04
- 2)杨辉三角[2]递归实现
- POJ 3126
- crontab中执行脚本中文乱码,手动执行没有问题的解决办法