Log in
updated 11:29 AM UTC, May 4, 2016

Missing radix parameter in Jquery

  • Written by Madhu V Rao
  • Published in Javascripts

Missing Radix Parameter is an warning you get when you use jQuery parseInt() without second parameter.

Here are some examples of the behaviour of Javascript on different inputs to parseInt function

     parseInt("10");      ---   produces 10

     parseInt("010")     ---   produces 8 (010 is Octal)

     parseInt("0x10")   ---  produces 16 (0x represents Hexadecimal numbers)

and so on , Jquery assumes the proper numbering system in the above cases.

But what if the number expected is supposed to be in Integer and user enters "010" which is valid representation of 10 in decimal?

The jquery will parse it as 8 and there are chances of miscalculations.

Hence , the second parameter is important and JSHint enforces it with error "Missing Radix Parameter".

(JSHint: static code checker for Javascripts).

These are some way to use the parseInt with second parameter i.e radix parameter:

parseInt("010", 10)   -  (10 represents decimal system) produces 10

parseInt("010", 2)     -  (2 represents Binary)  produces 2

parseInt("010", 8)     - (8 represents Octal) produces 8

parseInt("010", 16)   - (16 represents Hexadecimal) produces 16.

 

 

 


Powered by Bullraider.com
Follow Us on Twitter
Find Us on Facebook
Follow Us on Google
Follow Us on Pinterest