String.prototype.valueOf()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

La méthode valueOf() renvoie la valeur primitive de l'objet String.

Exemple interactif

const stringObj = new String("foo");

console.log(stringObj);
// Expected output: String { "foo" }

console.log(stringObj.valueOf());
// Expected output: "foo"

Syntaxe

js
str.valueOf();

Valeur de retour

Une chaîne de caractères qui représente la valeur primitive d'un objet String.

Description

La méthode valueOf() de String renvoie la valeur primitive de l'objet String sous la forme d'une chaine de caractères. Cette valeur est équivalente à String.prototype.toString().

Cette méthode est généralement appelée en interne par JavaScript et non explicitement dans du code.

Exemples

js
var x = new String("Coucou monde");
console.log(x.valueOf()); // affiche "Coucou monde"

Spécifications

Specification
ECMAScript® 2025 Language Specification
# sec-string.prototype.valueof

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
valueOf

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi