+ 9
parseInt() In JS?
What is the use of parseInt() In JS?
5 Respostas
+ 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";
+ 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!
+ 7
Thanks Brains. I understand that.
+ 7
Thank you so much Warith Vatanaplachaigoon your question helped me...
+ 2
it is numbers without letters