+ 1

What is parseint..,and where to use...

10th May 2018, 6:35 PM
M V Reddy
M V Reddy - avatar
2 Answers
+ 2
> parseInt(10)=>10 > parseInt(10, 16)=>16 > parseInt(10, 2)=>2 > parseInt(10, 3)=>3 > parseInt("10")=>10 > parseInt("10", 16)=>16 > parseInt("0x10")=>16 > parseInt("0x10", 10)=>0 > parseInt("0hello10")=>0 > parseInt("10hello10")=>10 > parseInt("0x10hello10")=>16 > parseInt("hello")=>NaN > parseInt("21", 2)=>NaN > parseInt("BAD")=>NaN > parseInt("BAD", 16)=>2989 > parseInt({a: 10})=>NaN > parseInt(Math.max)=>NaN So, briefly, parseInt tries to give you a number out of arbitrary input. If it finds anything meaningful, it returns it. If it doesn't - you get NaN. You can optionally provide second argument representing the radix to be used for parsing. If you don't, parseInt tries to guess it from the prefixes.
10th May 2018, 6:41 PM
MsJ
MsJ - avatar