parseInt function in javascript

Here we take some examples of parseInt()


If there is a string like "The Digit is 50" the answer in the parseInt() is 50

document.write(parseInt(" The Digit is 50 "));


If there is a floating point number:

document.write(parseInt(" 5.22 "));

Answer: 5

If the string begins with "0x", the answer will be 16

document.write(parseInt("0x10"));

If the string begins with "0", the answer will be 8 

document.write(parseInt("010"));

and if it is:

document.write(parseInt("013"));

The answer will be 11






Ebook Download
View all
Learn
View all