JS変数タイプ

1458 ワード

 typeof          
1、number     
    :1.      
  -Infinity(   ) "number"
  0 "number"
  NaN "number"
  eg:
    var num = 20;
    console.log(typeof num);
  //       
    num = 3.14;
    console.log(num); 
    num = -3/0;
  //Infinity
    console.log(num,typeof num);
    num = 0/3;
    console.log(num,typeof num);

    num = 0/0;
    console.log(num,typeof num);

2、boolean     
      2   true/false;
  console.log(5 > 3);
  console.log(5 < 3);

3、string       
                          string
    :
  var english = 'Hello';
  var chinese = '     ,       !!';
  var jp = "の";
  console.log(english,typeof english,chinese,typeof chinese,jp,typeof jp);

4、null      
    :
  var obj = null;
  console.log(obj);

5、undefined  undefined  
         
    :
  var x;
  console.log(x, typeof x);
  console.log(y);//y is not defined

6、object      
                 :
    :
   var arr = [1, 2, 3];
   var obj = {'userName': '  '};
   console.log(obj, typeof obj);
   console.log(arr, typeof arr);

7.     
  =:                     
    var num = 20;
  ==:           
     var num = 20;
     var num1 = '20';
     console.log(num == num1);
  ===:           (    )
 
  js       :                 
                                     
    :
    var num = 20;
    console.log(num, typeof num);//number
    num = 'の';
    console.log(num, typeof num);//string