JavaScript 之 ECMAScript[基础]

8种基本的数据类型(7种原始类型和1种复杂类型)

  Number  String  Boolean  Undefined  Null  Object  BigInt(了解)  Symbol(了解)

typeof 操作符

  因为JavaScript的数据类型是动态的,所以需要一种手段来确定任意变量的数据类型,由此产生了typeof

  对未定义的值 : 返回  undefined

  对布尔值   : 返回  boolean

  对字符串值  : 返回  string

  对数值    :  返回 number

  对对象(不是函数)或null :  返回  object 

  对函数    :  返回 function

  对符号值   :  返回 symbol

  <script>
    // 1.typeof基本演练
    var info 
    console.log('undefined:'+ typeof info )  //undefined:undefined

    var info = "why"
    console.log('字符串:'+ typeof info )  //字符串:string

    info = 18
    console.log('数字:'+ typeof info ) //数字:number

    info = {}
    console.log('对象:'+ typeof info )  //对象:object

    info = null
    console.log('null:'+ typeof info )  //null:object
    
    function fn(){
      return a + b
    }
    console.log('函数:' + typeof fn);  //函数function

    var a = true 
    console.log('布尔值:' + typeof a);  //布尔值:boolean
  </script>

 

  

 

posted @ 2022-09-23 15:51  杨建鑫  阅读(14)  评论(0编辑  收藏  举报