JavaScript valueOf()Method
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
![]()
![]()
![]()
![]()
![]()
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>
var str="Hello world!";
document.write(str.valueOf());
</script>
The output of the above example is:
Hello world!
Try it Yourself »
JavaScript String Object Other Extensions