Is parseInt() supposed to work like this?

前端 未结 7 1913
不思量自难忘°
不思量自难忘° 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:44

    It's documented to behave like that:

    If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point.

    Whether that behaviour is a good idea is another matter, but it's too late to change it now.

提交回复
热议问题