zoukankan      html  css  js  c++  java
  • js数据类型1

    1. 分类(2大类)

    • 基本(值)类型——5种
      • Number: 任意数值
      • String: 任意文本
      • Boolean: true/false
      • undefined: undefined
      • null: null
    • 对象(引用)类型——2种
      • Object: 任意对象
      • Array: 特别的对象类型(下标/内部数据有序)
      • Function: 特别的对象类型(可执行)

    2. 判断

    • typeof:
      • 可以区别: 数值, 字符串, 布尔值, undefined, function
      • 不能区别: null与对象, 一般对象与数组
    • instanceof
      • 专门用来判断对象数据的类型: Object, Array与Function
    • ===
      • 可以判断: undefined和null
    1. 基本类型
     // typeof: 返回的是数据类型的 字符串 形式
    
     //1. 基本类型
    
      var a
      console.log(a, typeof a, a===undefined) // undefined , 'undefined' , true
      console.log(a===typeof a) // false
    
    
      a = 3
      console.log(typeof a === 'number')  //true
    
    
      a = null
      console.log(typeof a) // 'object'
    
    //2. 对象类型
    
    
    

    var arr = [1,2,3];
    typeof arr // "object"

    var obj={name:'dada'};
    typeof obj // "object"

    var test = null;
    typeof test // "object"

    var fun= function(){};
    typeof fun // "function"

    typeof 检测一般对象、数组、null结果都是"object".
    此时用 instanceof 
    

    arr instanceof Array //true
    obj instanceof Object //true

  • 相关阅读:
    hadoop集群搭建
    javamail
    编码之后的字符串和数组长度解惑
    后台架构剖析
    搜索引擎选择: Elasticsearch与Solr
    WHRER条件里的数据类型必须和字段数据类型一致
    Phantomjs
    倒排索引
    Gremlin--一种支持对图表操作的语言
    Android Intent 用法全面总结
  • 原文地址:https://www.cnblogs.com/maizilili/p/12365358.html
Copyright © 2011-2022 走看看