Number类型和相关语法

2020-07-01  本文已影响0人  练习时长2年半的个人练习生

Number类型

    var n1 = new Number('123')
    console.log(n1 === 123) //false
    console.log(n1 == 123)//true
    let n2  =Number('123')
    console.log(n2)
    console.log(Number.isNaN(NaN))//true
    console.log(Number.isNaN(123))//false
    console.log(Number.isNaN('str'))//false
    console.log(typeof NaN) //number
   console.log(Number.parseInt('34234')) //34234
     console.log(Number.parseInt('34234.435434'))//34234
     console.log(Number.parseInt('sdfjkl'))//NaN
    console.log(Number.parseInt('55dsfsd434')) //55
 console.log(Number.parseInt('dfsf4455dsfsd434'))NaN
   console.log(Number.parseFloat('123.555')) //123.555
     console.log(Number.parseFloat('123'))//123
     console.log(Number.parseFloat('4455dsfsd')) //445
   console.log(Number.parseFloat('4455dsfsd434')) //4455
   console.log(Number.parseFloat('dfsf4455dsfsd434'))NaN
    console.log(Number.isInteger(45))//true
    console.log(Number.isInteger(45.0))//true
    console.log(Number.isInteger(45.34))//false
    console.log(Number.isInteger('DSFSAF'))//false
上一篇下一篇

猜你喜欢

热点阅读