您的位置:首页 > 其它

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'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: