AppDividend
Latest Code Tutorials

Javascript String valueOf Example | String.prototype.valueof()

0

Javascript string valueOf() is an inbuilt function that is used to return a value of the given string. The string valueOf() method returns a primitive value of the String object. The valueof() method is usually called automatically by JavaScript behind the scenes, and not explicitly in code.

Javascript String valueOf

The string represents the primitive value of a given String object. The JS valueof() returns the primitive value of a String object. See the following syntax of Javascript valueOf() function.

#Syntax

string.valueOf()

The function does not take any parameters.

See the following example.

// app.js

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

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 String.proptotype.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();
console.log(res);

See the following output.

String.prototype.valueof()

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

Finally, Javascript string valueOf example | String.prototype.valueof() is over.

Leave A Reply

Your email address will not be published.

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