Data type and data type conversion

 

Basic data types

  • Digital number
  • String string
  • Boolean boolean
  • null
  • undefined

Reference data types

  • Objects
    • Ordinary objects Object
    • Array Object Array
    • Regular objects RegExp
    • Date Object Date
    • ...
  • Function function
  • ...

Special type

symbol, represents a unique value

var a = Symbol('abc'); 
var b = Symbol('abc'); 
console.log(a==b); =>false

 

Other types of digital converted (Number)

  • Number (string)

Number The ('13 '); -> 13 is 
Number The ( ' 13px '); -> NaN3 // encountered as a result of non-significant digits NaN3 
Number The ('13 .5'); -> 13.5 // can be identified decimal

 

  • Number (Boolean)

Number(true); //->1 
Number(false); //->0

 

  • Number(null和undefined)

    Number(null); //->0 
    Number(undefined); //->NaN

     

  • Number (reference type): toString first reference value into a string retrieved, and then the string is converted to a digital Number.

  • parseInt和parseFloat

    parseInt('13.5px'); //=>13 
    parseFloat('13.5px'); //=>13.5
    parseInt('px123');//NaN

To convert other types to boolean (Boolean ())

Law: convert only false 0 / NaN / empty string / null / undefined, the rest is true.

 

Guess you like

Origin www.cnblogs.com/wangshouren/p/11615818.html