Javascript - Parsing numbers
Code Life
By Pierre Marsaa
Introduction to parseInt()
Sometimes you have a number stored as a string (like "42"), but you need to use it as an actual number to do math with it. That's where parseInt() comes in!
parseInt() is a function that converts a string into an integer (a whole number without decimals).
↗️
Loading editor...
↶
↷
Notice how "25" (a string) becomes 25 (a number). Without parseInt(), trying to add 1 to "25" would give you "251" (string concatenation), not 26!
Why is it called parseInt?
The name comes from "parse" (analyze and convert) and "int" (short for integer, which is a whole number).
Verify