js 类型转换和为空判断

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

  1. 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

  1. 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

  2. “” 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

  3. " " 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

  4. 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值