Is parseInt() supposed to work like this?

前端 未结 7 1928
不思量自难忘°
不思量自难忘° 2020-12-17 23:15

If I write this script :

alert(parseInt(\"123blahblahblah456\"));

I get the alert with the value 123

Ideally, shouldn\'t th

7条回答
  •  悲哀的现实
    2020-12-17 23:22

    As far as I know the parseInt() method is trying to parse until it finds a character. So if you have

    • parseInt("123 Iam funny") it will return 123.
    • parseInt("whats up 4711") it will return NaN

    Some documentation you might be checking out :

    • http://www.devguru.com/technologies/ecmascript/quickref/parseint.html
    • http://www.bennadel.com/blog/2012-Exploring-Javascript-s-parseInt-And-parseFloat-Functions.htm

提交回复
热议问题