Summary of data types in JavaScript
Basic Data Types:
- string
- number
- boolean
- object
- undefined
Boolean of Data Types
Each data type has its own boolean representations:
- string: more than one character -> true, zero character->false
- number: non-zero -> true, zero -> false
- boolean: true -> true (1), false -> false (0)
- object: non-null object -> true
- null, undefined, NaN: always false
Data Type conversion
- to string: X + ""
- to number: X-0
- to boolean: !!X
X |
typeof X |
boolean |
! X |
!! X |
X+"" |
X+0 |
X-0 |
parseInt(X) |
|
X |
typeof X |
X==0 |
X==1 |
X=="" |
X=="0" |
X=="1" |
X=="t" |
X==true |
X==false |
X==null |
X+0==1 |
X-0==1 |
|
X |
typeof X |
X===0 |
X===1 |
X==="0" |
X==="1" |
X===true |
X===false |
X===null |
X===NaN |
| |