JS - parseInt / Number 对 null. undefined .空字符 '' 转换结果

时间:2021-01-14 10:34:36   收藏:0   阅读:0
parseInt(‘‘)
NaN
parseInt(null)
NaN
parseInt(undefined)
NaN
parseInt(‘asdfa‘)
NaN
parseInt(‘123‘)
123
parseInt(‘asd12‘)
NaN
// 转换后只保留前面数字
parseInt(‘1213ewer‘) 
1213
parseInt(false)
NaN

Number(‘‘)
0
Number(null)
0
Number(false)
0
Number(undefined)
NaN


Number(-1)
-1
parseInt(-1)
-1
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!