Re: why math wont work?
"Dauber!" <dau_ber@verizo n.SPAMISFOREATI NG.net.invalid> writes:
[color=blue]
> Uhhh....yes. Believe it or not, despite popular belief, not all browsers
> interpret JavaScript the same way, including two of the ones I use.[/color]
Could you be persuaded to tell us what browsers those are?
If prefix plus isn't working consistently accross browsers, we should
ofcourse make a note of it.
The expected behavior (from the ECMAScript standard) is to be equivalent
to calling the Number function, but without the overhead of a function call.
[color=blue]
> Funny...two references I checked, including one that helped me get an A in
> my JavaScript programming class that I took for my webmaster admin
> certification, indicates that it's perfectly valid;[/color]
It is valid.
[color=blue]
> in fact, I'm given several overloaded versions tht account for "0x"
> format as well as binary and octal...[/color]
Overloaded?
Anyway, it is the collective experience in this group, that people
using parseInt most likely expect it to convert from base 10. That is
why we recommend also passing the radix to the function, to avoid
surprises when a user entered number starts with zero.
If you know what you are doing, using parseInt without the radix is
correct. It's just not good advice to a beginner without telling why
"089" converts to 0 in some browsers and 89 in others.
Not all browsers accept octal numbers as arguments to parseInt (as,
indeed, they shouldn't according to ECMA 262). But IE does. So any way
you put it, omitting the radix will make your page behave inconsistently
across browsers.
/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
"Dauber!" <dau_ber@verizo n.SPAMISFOREATI NG.net.invalid> writes:
[color=blue]
> Uhhh....yes. Believe it or not, despite popular belief, not all browsers
> interpret JavaScript the same way, including two of the ones I use.[/color]
Could you be persuaded to tell us what browsers those are?
If prefix plus isn't working consistently accross browsers, we should
ofcourse make a note of it.
The expected behavior (from the ECMAScript standard) is to be equivalent
to calling the Number function, but without the overhead of a function call.
[color=blue]
> Funny...two references I checked, including one that helped me get an A in
> my JavaScript programming class that I took for my webmaster admin
> certification, indicates that it's perfectly valid;[/color]
It is valid.
[color=blue]
> in fact, I'm given several overloaded versions tht account for "0x"
> format as well as binary and octal...[/color]
Overloaded?
Anyway, it is the collective experience in this group, that people
using parseInt most likely expect it to convert from base 10. That is
why we recommend also passing the radix to the function, to avoid
surprises when a user entered number starts with zero.
If you know what you are doing, using parseInt without the radix is
correct. It's just not good advice to a beginner without telling why
"089" converts to 0 in some browsers and 89 in others.
Not all browsers accept octal numbers as arguments to parseInt (as,
indeed, they shouldn't according to ECMA 262). But IE does. So any way
you put it, omitting the radix will make your page behave inconsistently
across browsers.
/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Comment