JavaScript parseInt() は、Java parseInt() と同じようには機能しないようです。
非常に簡単な例は次のとおりです。
document.write(parseInt(" 60 ") + "<br>"); //returns 60
document.write(parseInt("40 years") + "<br>"); //returns 40
document.write(parseInt("He was 40") + "<br>"); //returns NaN
1号線は大丈夫です。しかし、実際には「年」を整数に変換できないため、2行目でエラーが発生すると予想されます。JavaScript parseInt() は、文字列の最初の数文字が整数かどうかをチェックするだけだと思います。
では、文字列に非整数がある限り、NaN が返されることを確認するにはどうすればよいでしょうか?