AppDividend
Latest Code Tutorials

Javascript String valueOf: String.prototype.valueof()

0

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 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 string represents the primitive value of a given String object. The valueof() returns the primitive value of a String object.

Syntax

See the following syntax of Javascript valueOf() function.

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 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.