zoukankan      html  css  js  c++  java
  • 数据类型的检测

    //1、 typeof
    var a = 12;
    typeof a// ---> 'number'
    typeof 'number' // ---> 'string'
    typeof true // ----> 'boolean'
    typeof 'true' // ---> 'string'
    typeof null // ---> 'object'
    typeof undefined // ---> 'undefined'
    typeof ({}) // ---> 'object'
    typeof ([]) // ---> 'object'

    //2、constructor

    var str = 'www';
    console.log(str.constructor.toString());
    console.log(a.constructor.toString());
    console.log(({}).constructor.toString());
    console.log(([]).constructor.toString());
    // console.log(null.constructor);

    //3、 instanceof 查看对象
    var obj = {};
    var ary = [];
    console.log(obj instanceof Array); // false
    console.log(ary instanceof Array); // true
    console.log(obj instanceof Object);// true
    console.log(ary instanceof Object);// true

    //4、Object.prototype.toString.call(xxx);
    console.log(Object.prototype.toString.call([]));
    console.log(Object.prototype.toString.call({}));
    console.log(Object.prototype.toString.call(/d/));
    console.log(Object.prototype.toString.call(12));
    console.log(Object.prototype.toString.call('www'));
    console.log(Object.prototype.toString.call(true));
  • 相关阅读:
    sort函数详解
    C++重载运算符的规则详解
    poj3061-subsequence
    员工管理系统 :练习
    Jdbc 模拟登陆系统的练习
    有关String 的常用方法
    浅谈希尔排序-----摘录
    简单选择排序
    typedef 和define 的区别
    写博客的理由
  • 原文地址:https://www.cnblogs.com/zhangyongxi/p/9553824.html
Copyright © 2011-2022 走看看