I have many doubts about parseInt, I can not understand anything

-1

I'm in a course to apply to a Programming school but for more I've searched, I can not understand the parseInt, could someone explain to me?

    
asked by Dannie Sarer 13.09.2018 в 06:32
source

1 answer

2

The MDN documentation has good information about the function parseInt .

Let's assume you have a text string with a number:

let numeroA = '10';

The variable numeroA contains a text string string , which contains the characters 11 . But this is not a number, it is a string of text which turns out to have numeric characters.

The parseInt() function can take this value and convert it to a number.

let numeroB = parseInt(numeroA);

Which will store a numeric data type in the variable numeroB .

The function parseInt() has many options like converting numbers in different bases (decimal, octal, hexadecimal), check if what is entered can not be interpreted as a number (for which the function would return a NAN ) .

    
answered by 13.09.2018 в 06:53