Javascript, why treated as octal

前端 未结 6 537
我在风中等你
我在风中等你 2020-12-06 20:58

I\'m passing as parameter an id to a javascript function, because it comes from UI, it\'s left zero padded. but it seems to have (maybe) \"strange\" behaviour?



        
6条回答
  •  悲哀的现实
    2020-12-06 21:43

    Leading 0s indicate that the number is octal.

    parseInt parses a string containing a number.
    parseInt(0000022115, 10) passes a numeric literal. The literal is parsed in octal by the JS interpreter, so you're passing a raw numeric value to parseInt.

提交回复
热议问题