Please explain parseInt() function

Hey guys,

I have tried to understand parseInt() function but it is not making sense still. Could someone explain it simply?

I have used this web page to understand, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt.
It said parseInt() " parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems)".

1 Like

Hey @Rob03, hope your ok.

Parseint basically to convert a string to integer (if the string have a decimal expersion).
Here a quick example:

var text = "test"
var stringNumber = "20"

console.log(parseInt(text)) //should return NaN
console.log(parseInt(stringNumber)) //should return 20

You can read more about here:
https://www.w3schools.com/jsref/jsref_parseInt.asp

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like