JSでの変数タイプ

7679 ワード

変数#ヘンスウ#
  • JSでtypeofを使用して得られるタイプ
    typeof undefined //undefined
    typeof 'abc' //string
    typeof 123 //number
    typeof true //boolean
    //        ,typeof            
    typeof {} //object
    typeof [] //object
    typeof null //object
    typeof console.log //function
    
  • は、==および==
    if (obj.a == null) {
      //     obj.a === null || obj.a === undefined     
      //   jqurey        
    }
    
  • をいつ使用するか
  • JSにはどのような内蔵関数がありますか
    Object
    Array
    Boolean
    Number
    String
    Function
    Date
    RegExp
    Error
    
  • JS変数は、格納方法によってどのようなタイプに分類され、その特徴を説明します.
  • 変数タイプ
  • 値タイプ
  • var a = 100
    var b = a
    a = 200
    console.log(b) //100
    
  • 参照タイプ
  • var a = { age: 20 }
    var b = a
    b.age = 21
    console.log(a.age) //21
    

  • JSON
    //JSON      JS  
    JSON.stringify({ a: 10, b: 20 })
    JSON.parse('{"a":10,"b":20}')
    
  • の理解方法
    変数計算-強制型変換
  • 文字列接合
    var a = 100 + 10 //110
    var b = 100 + '10' //'10010'
    
  • ==演算子
    100 == '100' //true
    0 == '' //true
    null == undefined //true
    
  • if文
    var a = true
    if (a) {
      //...
    }
    var b = 100
    if (b) {
      //...
    }
    var c = ''
    if (c) {
      //...
    }
    
  • 論理演算子
    console.log(10 && 0) //0
    console.log('' || 'abc') //'abc'
    console.log(!window.abc) //true
    //          true  false
    var a = 100
    console.log(!!a) //true