String to Integer Conversion in JavaScript

String to Integer Conversion in JavaScript
Rating: 5 - 1 Votes

String to Integer Conversion in JavaScript

JavaScriptWe have seen in previous tutorial that JavaScript treat a number as a string if you assign it using quotation marks.  Instead of addition of 2 numbers, it will perform concatenation.  To overcome this issue, we make use of parseInt() function in JavaScript.  This function will convert string to integer.  Example is given below.

Note:  If you try to retrieve a value within textbox using JavaScript, then that value will also be treated as a string.  So, you have to perform string to integer conversion to do calculation.