[Javascript] sort replace question

liorean liorean at gmail.com
Tue Feb 28 11:20:13 CST 2006


On 28/02/06, Michael Borchers <list at tridemail.de> wrote:
> what's wrong then?! :(
>
>  var y = 3.5;
>  var x = parseFloat(y);

This is entirely unnecessary. y isn't a string, it's a number.
parseFloat takes a string, and parses it to a number. So, what happens
is that y is autocast into a string and then that string is parsed
into a float.

>  var z = toString(y);
toString is a method, not a function. Since you aren't specifying an
object, it will be resolved as a variable. Since properties of the
window object are also variables in the global scope, you're
effectively calling window.toString here.

>  alert(z);
> gives out: [object Window]
Naturally. Nothing else is to be expected.


var
    a="12.75", // a is of type string
    b=parseFloat(a), // b is of type number
    c=Number(a), // c is of type number
    d=String(b), // d is of type string
    e=c.toString(), // e is of type string
    f=''+b, // f is of type string
    r=/\./g;

alert(d.replace(r,'_')); // ==> 12_75
--
David "liorean" Andersson
<uri:http://liorean.web-graphics.com/>



More information about the Javascript mailing list