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
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
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 GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
valueOf |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support