JavaScript String valueOf() Function

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.



The function does not take any parameters.


// app.js

let data = "Krunal Lathiya";
let res = data.valueOf();

See the output.

Javascript String valueOf Tutorial

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.

// app.js

let data = new String('Ankit Lathiya');
let res = data.valueOf();

See the following output.


The Javascript valueOf() method does not change the value of the original string.

That’s it.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.