What is the difference between parseInt() and Number()?

前端 未结 10 978
無奈伤痛
無奈伤痛 2020-11-22 12:02

How do parseInt() and Number() behave differently when converting strings to numbers?

10条回答
  •  星月不相逢
    2020-11-22 12:30

    I found two links of performance compare among several ways of converting string to int.

    parseInt(str,10)    
    parseFloat(str)
    str << 0
    +str
    str*1 
    str-0
    Number(str)
    

    http://jsben.ch/#/zGJHM

    http://phrogz.net/js/string_to_number.html

提交回复
热议问题