-4

The `parseInt() function can return undesired and/or unexpected results if the radix is not supplied.Please make a radix is used on all parseInt() instances.

how to edit it

please helpme

i will send file if you need it

Dwi Syaputra
  • 31
  • 1
  • 2
  • 2
    Show code please? What is the problem? – Jonathan Lam Nov 01 '15 at 19:38
  • "*how to edit it*" - with a text editor? – melpomene Nov 01 '15 at 19:38
  • jonathan . what is your mail iwill send it. more than one file – Dwi Syaputra Nov 01 '15 at 19:43
  • This http://stackoverflow.com/questions/10398834/using-javascript-parseint-and-a-radix-parameter is related, if not a duplicate. If you don't understand it, please add a small example to your question and explain precisely what you don't know or understand. (No need to email complete source file around.) – WhiteViking Nov 01 '15 at 21:24

2 Answers2

0

Assuming you want to create an Error when a radix is not passed,

  1. Shadow parseInt, keeping the old reference in a closure such as an IIFE
  2. Test for your conditions
  3. Invoke the old reference

For example

parseInt = (function (old_parseInt) {
    return function parseInt(x, radix) {
        if (arguments.length < 2)
            throw new TypeError('parseInt must be given a radix');
        return old_parseInt.apply(this, arguments);
    };
}(parseInt));

Then in usage,

parseInt('12', 8); // 10
parseInt('12'); // TypeError: parseInt must be given a radix

(Running this code on this page will break stackoverflow, be warned)

Paul S.
  • 64,864
  • 9
  • 122
  • 138
0

The radix is the second parameter to the parseInt() function. It sets the numerical base that should be used when converting the string to an integer.

Obviously you would expect parseInt('11') to always return 11 :) This is not guaranteed by all various JavaScript implementations.

What is guaranteed though is that parseInt('11', 10) will always return that 11 that you'd expect "by instinct".

Choosing a different radix ( or working in an implementation that has a different default for that matter ) say 2 would mean that the number is interpreted relative to base 2 => parseInt('11') would actually mean parseInt('11', 2) and hence come out to 3.

Armin Braun
  • 3,645
  • 1
  • 17
  • 33