How does parseInt() in Javascript work?

后端 未结 4 1496
挽巷
挽巷 2021-01-28 12:25



        
4条回答
  •  悲&欢浪女
    2021-01-28 13:16

    You only get number till where it is meaningful when converting from string to number.

    console.log(parseInt('01abbb')) // 1 -> it is started by 01 before chars
    console.log(parseInt('31xyz'))  // 31 -> it is started by 31 before chars
    console.log(parseInt('zyz31'))  // NaN -> it is not started by numbers
    console.log(parseInt('31xyz1')) // 31 -> it is started by 31 before chars
    

提交回复
热议问题