js 类型转换和为空判断
1.undefined test**********
var num
console.log(num):undefined
num=undefined:true
num=null:false
Boolean(num):false
isNaN(num):true // isNaN()函数,判断undefined为true,NaN和undefined 不相等
Number(num):NaN
parseInt(num):NaN
parseInt(num,16):NaN
parseFloat(num):NaN
parseFloat(“bbbb”):NaN
NaN==undefined:false
2.null test**********
var num=null
console.log(num):null
num=undefined:false
num=null:true
Boolean(num):false
isNaN(num):false
Number(num):0
parseInt(num):NaN
parseInt(num,16):NaN
parseFloat(num):NaN
3.“11aa” test**********
var num=“11aa”
console.log(num):11aa
num=undefined:false
num=null:false
Boolean(num):true
isNaN(num):true
Number(num):NaN
parseInt(num):11
parseInt(num,16):4522
parseFloat(num):11
4.“a1a” test**********
var num=“a1a”
console.log(num):a1a
num=undefined:false
num=null:false
Boolean(num):true
isNaN(num):true
Number(num):NaN
parseInt(num):NaN
parseInt(num,16):2586
parseFloat(num):NaN
- 123 test**********
var num=123
console.log(num):123
num=undefined:false
num=null:false
Boolean(num):true
isNaN(num):false
Number(num):123
parseInt(num):123
parseInt(num,16):291
parseFloat(num):123
6.“0x32” test**********
var num=“0x32”
console.log(num):0x32
num=undefined:false
num=null:false
Boolean(num):true
isNaN(num):false
Number(num):50
parseInt(num):50
parseInt(num,16):50
parseFloat(num):0
-
0x32 test**********
var num=0x32
console.log(num):50
num=undefined:false
num=null:false
Boolean(num):true
isNaN(num):false
Number(num):50
parseInt(num):50
parseInt(num,16):80
parseFloat(num):50 -
“” test空串**********
var num=""
console.log(num):
num=undefined:false
num=null:false
Boolean(num):false
isNaN(num):false
Number(num):0
parseInt(num):NaN
parseInt(num,16):NaN
parseFloat(num):NaN -
" " test空格**********
var num=" "
console.log(num):
num=undefined:false
num=null:false
Boolean(num):true
isNaN(num):false
Number(num):0
parseInt(num):NaN
parseInt(num,16):NaN
parseFloat(num):NaN -
0 test零**********
var num=0
console.log(num):0
num=undefined:false
num=null:false
Boolean(num):false
isNaN(num):false
Number(num):0
parseInt(num):0
parseInt(num,16):0
parseFloat(num):0