The valueOf() method of the String class in JavaScript returns the primitive value of the specified string object.
The syntax of String.valueOf() method is:
valueOf()
This valueOf() method of String returns the primitive value of the specified object. Overrides the Object.prototype.valueOf() method.
String.valueOf() returns value of type String
.
In JavaScript, the valueOf()
method returns the primitive value of a string object.
For example,
strObj
using the String()
constructor.valueOf()
method on strObj
.strObj
is stored in the variable primitiveValue
.primitiveValue
to the console using the console.log()
method.const strObj = new String('Hello');
const primitiveValue = strObj.valueOf();
console.log(primitiveValue);
Hello
In this JavaScript tutorial, we learned about valueOf() method of String: the syntax and few working examples with output and detailed explanation for each example.