JavaScript String valueOf()

Example

Get the value of a text:

let text = "Hello World!";
let result = text.valueOf();
Try it Yourself »

The same as:

let text = "Hello World!";
let result = text;
Try it Yourself »

More examples below.


Description

The valueOf() method returns the primitive value of a string.

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

The valueOf() method can be used to convert a string object into a string.

See Also:

The toString() Method

Note

The valueOf() method is the default method for JavaScript strings.

It is used internally by JavaScript.

Normally, you will not use it in your code.


Syntax

string.valueOf()

Parameters

NONE

Return Value

Type Description
A stringThe primitive value of the string.


More Examples

Get the value of a String object:

let text = new String("Hello World!");
let result = text.valueOf();
Try it Yourself »

Browser Support

valueOf() is an ECMAScript1 (ES1) feature.

ES1 (JavaScript 1997) is fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.