The valueOf() method in JavaScript is usually called automatically by JavaScript behind the scenes and not explicitly in code.
JavaScript String valueOf
Javascript String valueOf() is a built-in function that returns a value of the given string. The string valueOf() method returns a primitive value of the String object.
The string represents the primitive value of a given String object. The valueof() returns the primitive value of a String object.
Syntax
string.valueOf()
The function does not take any parameters.
Example
// app.js let data = "Krunal Lathiya"; let res = data.valueOf(); console.log(res);
See the output.
The valueOf() method of String returns a primitive value of the String object as a string data type. This value is equivalent to the Sprototypetotype.toString method.
Let’s see one more example to print the primitive value of the string object.