Java Reference
In-Depth Information
Table 4-8.
The List of Value Types and Their Corresponding Converted String Values
Value Type
Converted String Value
Undefined
"undefined"
Null
"null"
Boolean
The Boolean value
true
is converted to “true” and
false
to “false”
Number
+0
,
0
, and
-0
are converted to “0”;
NaN
is converted to “NaN”;
Infinity
(or
+Infinity
) is converted to “Infinity”;
-Infinity
is converted to
“-Infinity”. All other numbers are converted to their corresponding string
representation in either decimal or scientific notation. Bigger numbers
may not be converted exactly
String
Identity conversion
Object
If the object is a wrapper for a primitive value, it returns the primitive
value as a String; otherwise, the String representation of the object by
calling the
toString()
method is returned. If
toString()
method does
not exist in the object, the string representation of the returned value of
the
valueOf()
method is returned
You can use the
String()
global function to explicitly convert a value to the
String type. The function takes the value to be converted as an argument and returns a
String. The following snippet of code contains some examples of implicit and explicit
conversions to the String type:
var result;
result = String(undefined);
print("undefined is converted to", result);
result = String(true);
print("true is converted to", result);
result = String(9088);
print("9088 is converted to", result);
result = String(0x786A);
print("0x786A is converted to", result);
result = String(900000000000000000000);
print("900000000000000000000 is converted to", result);
result = String(9000000000000000000000);
print("9000000000000000000000 is converted to", result);
result = String(new Object(1982));
print("new Object(1982) is converted to", result);
Search WWH ::
Custom Search