JavaScript valueOf()Method

String 对象参考手册JavaScript String Object

Definition and Usage

The valueOf() method returns the primitive value of a String object.

Note:The valueOf() method is usually called automatically by JavaScript in the background, rather than being explicitly written in code.

Syntax

string.valueOf()


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the valueOf() method.


Example

Example

Return the primitive value of a String object:

<script>

var str="Hello world!";
document.write(str.valueOf());

</script>

The output of the above example is:

Hello world!

Try it Yourself »


String 对象参考手册JavaScript String Object Other Extensions