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
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
Assuming you want to create an Error when a radix is not passed,
parseInt
, keeping the old reference in a closure such as an IIFEFor 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)
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.