-1

I have a piece of javaScript code as :

var val = parseInt("08");
alert("Val : " + val);

It displays val as 0.

Where as the same piece of code in iOS displays 8.

Can someone shed more light on this issue ?

Thanks.

Biranchi
  • 16,120
  • 23
  • 124
  • 161

1 Answers1

1

It's because you are using parseInt without defining which radix to use. Now it thinks you are using 8 as the radix.

Try this:

var val = parseInt('08', 10);
thebreiflabb
  • 1,504
  • 10
  • 19