美文网首页
typeof返回哪些数据类型?

typeof返回哪些数据类型?

作者: 智多牛 | 来源:发表于2016-12-20 13:57 被阅读0次

/**
* 布尔
*/
var b = true;

    console.log(typeof b);   //输出:boolean
    
    
    /**
     * 字符
     */
    var s = '小明';
    
    console.log(typeof s);   //输出:string
    
    
    /**
     * 数字
     */
    var n = 1;
    
    console.log(typeof n);   //输出:number
    
    
    /**
     * 数组
     */
    var arr = [];
    
    console.log(typeof arr); //输出:object
    
    
    /**
     * 对象
     */
    var obj = {};
    
    console.log(typeof obj);  //输出:object
    
    
    /**
     * 函数
     */
    function fun(){};
    
    console.log(typeof fun);  //输出:function
    
    
    /**
     * 不存在的变量
     */
    console.log(typeof boy);  //输出:undefined
    
    
    /**
     * 未赋值的变量
     */
    var age;
    
    console.log(typeof age); //输出:undefined

相关文章

网友评论

      本文标题:typeof返回哪些数据类型?

      本文链接:https://www.haomeiwen.com/subject/thnxvttx.html