String.prototype.toString()
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 toString()
renvoie une chaine de caractères représentant l'objet renseigné.
Exemple interactif
const stringObj = new String("foo");
console.log(stringObj);
// Expected output: String { "foo" }
console.log(stringObj.toString());
// Expected output: "foo"
Syntaxe
str.toString();
Valeur de retour
Une chaîne de caractères représentant la chaîne appelante.
Description
L'objet String
surcharge la méthode toString()
de l'objet Object
; il n'hérite pas de Object.prototype.toString()
. Pour Les objets String
, la méthode toString()
renvoie une chaine de caractères représentant l'objet, et est similaire à la méthode String.prototype.valueOf()
.
Exemples
L'exemple suivant affiche la valeur textuelle d'un objet String
:
var x = new String("coucou monde");
console.log(x.toString()); // affiche "coucou monde"
Spécifications
Specification |
---|
ECMAScript® 2025 Language Specification # sec-string.prototype.tostring |
Compatibilité des navigateurs
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toString |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support