Java Reference
In-Depth Information
answer = +"5";
<< 5
typeof answer;
<< "number"
Yet another way to convert a string into a number is to use the Number function:
Number("23");
<< 23
This is the preferred way to convert strings to numbers as it avoids type coercion in the
background. The conversion is explicit, making it obvious what is being done.
Converting Numbers to Strings
To change numbers into strings you can add an empty string, which will use type coercion
to silently convert the number into a string in the background:
3 +'';
<< "3"
The preferred way, however, is to use the String function:
String(3);
<< "3"
There is also the very similar toString() method, but this may change the base of the
number. For example, if you want to write the number 10 in binary (base two), you could
write:
> 10..toString(2):
<< "1010"
You can go up to base 36, although after base ten, letters are used to represent the digits:
Search WWH ::




Custom Search