[thelist] JS Question
Joe Crawford
jcrawford at avencom.com
Thu Apr 12 11:42:53 CDT 2001
Salvatore Palmisano wrote:
> My JS isnt what it should be, and I cant seem to figure out why this isnt
> working:
> <SCRIPT type="text/javascript">
> <!--
>
> var x, y;
> x = 3;
>
> y = x.toString(8);
> document.writeln(y);
> document.writeln(x);
>
> -->
> </SCRIPT>
>
> to.String(y) is supposed to convert the number to the y format (8 being
> octal) isnt it?
> Currently the writeln(x) and writeln(y) lines are outputting the same thing.
My JavaScript reference (the O'Reilly 3rd Ed. says that toString() does
not take any arguments. So your toString(8) doesn't do anything.
I'll follow along with your code with comments about what's happening...
var x, y; //x and y exist
x = 3; // x = 3; an integer
y = x.toString(8); // y = "3"; which is x converted to a string,
// the argument '8' is ignored
document.writeln(y); // 3 is printed
document.writeln(x); // 3 is printed
An octal would be a number beginning with 0 (always) and including 0-7
after.
Now, here:
http://www.devguru.com/technologies/ecmascript/quickref/number.html
it says that that parameter is meaningful...
Syntax: object.toString([radix])
toString method
This method returns a string representing the Number object, and is
called by JavaScript whenever the code requires a string value. The
optional 'radix' parameter is an integer between 2 and 36 which
specifies the base to be used when representing numeric values. This
method overrides the Object.toString method.
But it also indicates that this is used in Netscape only. I am not sure
what's in the ECMA Specifications on this issue. :-(
Once again, the moving target that is JavaScript, moves again. :-\
- Joe
--
Joe Crawford |||||||||||||| mailto:jcrawford at avencom.com
|||||||||||||||||||||||| http://www.avencom.com
||||||||||||||||||||||||||| Avencom: Set Your Sites Higher
More information about the thelist
mailing list