parseInt() In JS? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9

parseInt() In JS?

What is the use of parseInt() In JS?

14th May 2018, 11:21 PM
Warith Vatanaplachaigoon
Warith Vatanaplachaigoon - avatar
5 Answers
+ 7
parseInt() extracts an integer/number from a given string. var a=parseInt("23h"); a is now 23; var a=parseInt("hallo"); a is now NaN since no int is available in "hallo";
14th May 2018, 11:35 PM
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - avatar
+ 8
Just to add to Brains , parseInt() will only be able to extract the integer from a given string if the string begins with an integer. Otherwise it still yields NaN, if the integer appears anywhere in the string but not the start. var a = parseInt('hello5'); var a = parseInt('hel5lo'); // all the above results NaN except if the integer begins as below: var a = parseInt('5hello'); // a is now 5 Happy Coding!
20th May 2018, 11:10 PM
Benneth Yankey
Benneth Yankey - avatar
+ 7
Thanks Brains. I understand that.
15th May 2018, 12:24 AM
Warith Vatanaplachaigoon
Warith Vatanaplachaigoon - avatar
+ 7
Thank you so much Warith Vatanaplachaigoon your question helped me...
19th May 2018, 9:48 AM
$hardul B
$hardul B - avatar
+ 2
it is numbers without letters
15th May 2018, 8:45 AM
mohamed sayah
mohamed sayah - avatar