String() (Function)

A String object constructor called as a function.


ECMAScript edition - 2
JavaScript - 1.2
JScript - 1.0
Internet Explorer - 3.02
Netscape - 4.0
Property/method value type:String primitive
JavaScript syntax:-String()
Argument list:aValueSome value to be converted to a string

When String() is called as a function rather than a constructor, it performs a type conversion.

The internal ToString conversion facilities are used for type conversion with the additional handling of a missing argument provided by the constructor itself.

No argumentAn empty string " "
BooleanIf the argument is true, then the result is "true" otherwise the result is "false"
NumberSpecial cases are provided for NaN and Infinity where "NaN" and "Infinity" will be returned. Otherwise the string is a textual representation of the value.
StringNo conversion, the input value is returned unchanged.
ObjectAn internal conversion to a primitive takes place followed by a conversion from that primitive to a string. Some objects will return a string value that is immediately useful.

The result of calling this function is a string version of the value passed in. If there is no value passed in argument an empty string is returned.


See also:Cast operator, Constructor function, constructor property, Implicit conversion, Number()


ECMA 262 edition 2 - section -

ECMA 262 edition 2 - section - 15.5.1

ECMA 262 edition 3 - section - 15.5.1

Wrox Instant JavaScript - page 36