• js 中的类型比较


    console.log(typeof 1)            // number
    console.log(typeof 'cc')        // string
    console.log(typeof true)        // boolean
    console.log(typeof undefined)     // undefined
    console.log(typeof null)        // object
    console.log(typeof NULL)         // undefined  NULL | Null 都不对
    console.log(typeof {})            // object
    console.log(typeof [])            // object
    console.log(typeof function(){})  // function 这个有点意料之外,本以为也是 object
    console.log(typeof Symbol())     // symbol

    // 以下:皆 true
    console.log(typeof true < typeof function(){} ? true : false); 
    console.log(
    typeof function(){} < typeof 1 ? true : false);
    console.log(
    typeof 1 < typeof {name:'cc'} ? true : false);
    console.log(
    typeof {name:'cc'} === typeof null ? true : false);
    console.log(
    typeof {name:'cc'} < typeof 'cc' ? true : false);
    console.log(typeof 'cc' < typeof Symbol() ? true : false); console.log(
    typeof Symbol() < typeof undefined ? true : false);

    // 基于多键值进行排序的时候或许可以用一下
    // boolean < function < number < object(null) < string < symbol < undefined

    // 负责任的揭秘一下: a b c d e f g h i j k l m n o p q r s t u v w x y z
    // 最后补充:不知道该被自己逗死,还是蠢死.. 誒
    console.log( typeof typeof [] ) // string
    • typeof 返回值是小写
    • null 小写,NULL Null 这些写法不对
    • 函数 typeof 返回值是 function。疑惑脸:什么时候 function 是 js 的基本类型了?
    • 这样说吧: typeof  是一个运算符,返回结果并不等同于 js 基本类型 (null 不等, function 看来也是)
    • js 中基本类型:
      boolean
      number
      object (Object | Function | Array | RegExp | ..)
      null
      string
      undefined
      symbol (ES6 新增)
    • typeof 的返回值:
      boolean  
      number
      string object (object | array | null)
      function
      undefined symbol
  • 相关阅读:
    ThinkPhp学习11
    ThinkPhp学习10
    1.自我介绍
    Axure高级教程--在原型中插入视频
    Axure制作iphone手机交互模型—覆盖切换
    对产品的一些总结
    详解Axure的Masters功能
    详解使用Axure 制作Tab切换功能
    产品经理的初识
    作为产品经理--如何写好PRD文档
  • 原文地址:https://www.cnblogs.com/yier0705/p/8085394.html
Copyright © 2020-2023  润新知