typeof和instanceof的用法

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'

 

posted on 2015-11-13 22:01  Bigmario  阅读(170)  评论(0编辑  收藏  举报