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));
  • 相关阅读:
    ARC管理内存(一)
    懒加载lazyload
    View的封装
    Plist文件与数据解析
    ubuntu16.04 安装python3.6
    ubuntu16.04 安装 wxPython方法
    第三章
    第二章
    协方差的意义
    内存区--Java
  • 原文地址:https://www.cnblogs.com/zhangyongxi/p/9553824.html
Copyright © 2011-2022 走看看