Lesson #8

radix parameter missing, parseInt()

parseInt(string, radix)




This is of course made with the assumption that you are trying to use the "Counting" or base 10 numbering system.


If you're using parseInt in your Javascript or JQuery project, chances are you forgot to use the radix parameter. I would like to say that you can get away with using this function without having to use that parameter, but perhaps its worthwhile to use it depending on what you're trying to accomplish.

Essentially if the string you're trying to parse into an integer has the possibility of a leading zero. E.g "010", which would be an octal and would be treated as such by default, meaning what you would get back is the binary equivalent which turns out to be: 2.

The radix parameter establishes which base number system you want to use so that you don't end up using the octal system by default. This could also be helpful if you are intentionally trying to use the other number systems like hexadecimal and such. (e.g. parseInt("0x01",16) which would output: 00000001).

Normally you want to just use the counting numbering system or base 10 in which case you just set the radix parameter to 10.



parseInt("-15", 10) = -15

parseInt("-0xF",16) = -15

parseInt("001 101", 8) = -15

parseInt("-17", 8) = -15

so, on and so forth.

To read more on the subject Mozilla does a splendid job of explaining further.

author: clearskyy





holla at us

ComputersCSSFoodGamesGearHardwareHealthHTMLHumorjQueryLaptopsMobileMoviesMusicMySQLNewsOnline ServiceOperating SystemPeripheralsPetsPHPRandomSoftwareSportsTV ShowsUnsortedVlog

Thanks for checking us out ♥

Hand coded with the blood, sweat, tears, and demonic infant sacrifices made by no other than Nate Seymour.


Icons made by Icomoon, SimpleIcon, Freepik, Madebyoliver, Google from www.flaticon.com is licensed by CC BY 3.0