一、5个falsy值
0
NaN
' '
null
undefined
二、类型转换
1.转换为字符串
number转换为string
var n = 1
undefined
n.toString()
"1"
1+''
"1"
''+1
"1"
var n = 1
undefined
window.String(n)
"1"
boolean转换为string
var b = true
undefined
b.toString()
"true"
true+''
"true"
''+true
"true"
window.String(true)
"true"
object转换为string
var object = {"name":"frank"}
undefined
object.toString()
"[object Object]"
object+''
"[object Object]"
''+object
"[object Object]"
window.String({})
"[object Object]"
null转换为字符串
window.String(null)
"null"
''+null
"null"
undefined转换为字符串
window.String(undefined)
"undefined"
''+undefined
"undefined"
2.转换为boolen值
Boolean(1)
true
Boolean(0)
false
Boolean('aaa')
true
Boolean('')
false
Boolean(' ')
true
Boolean(null)
false
Boolean(undefined)
false
Boolean({})
true
Boolean({name:"frank"})
true
!!true
true
!!false
false
!!"123"
true
!!''
false
!!' '
true
!!null
false
!!undefined
false
!!{}
true
!!{name:'frank'}
true
3.转换为Number
Number('1')
1
parseInt('1.23',10)
1
parseFloat('2.3334')
2.3334
'1'-0
1
'1.23'-0
1.23
+'1.23'
1.23
+'-3.566'
-3.566
-(-'1')
1
-(-'-1')
-1
parseInt('011')
11
parseInt('011',8)
9
parseInt('011',16)
17
parseInt('s')
NaN
parseInt('1s')
1
parseInt('12s')
12
三、四个关于内存的题目
四、垃圾回收