[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/String/toString [Back]  [Original]

String.prototype.toString() - JavaScript | MDN

Cette page a t traduite partir de l'anglais par la communaut. Vous pouvez contribuer en rejoignant la communaut francophone sur MDN Web Docs.

View in English Always switch to English

String.prototype.toString()

Baseline Large disponibilit

Cette fonctionnalit est bien tablie et fonctionne sur de nombreux appareils et versions de navigateurs. Elle est disponible sur tous les navigateurs depuis juillet 2015.

La mthode toString() renvoie une chaine de caractres reprsentant l'objet renseign.

Dans cet article

Exemple interactif

const stringObj = new String("foo");

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

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

Syntaxe

js
str.toString();

Valeur de retour

Une chane de caractres reprsentant la chane appelante.

Description

L'objet String surcharge la mthode toString() de l'objet Object ; il n'hrite pas de Object.prototype.toString(). Pour Les objets String, la mthode toString() renvoie une chaine de caractres reprsentant l'objet, et est similaire la mthode String.prototype.valueOf().

Exemples

L'exemple suivant affiche la valeur textuelle d'un objet String :

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

Spcifications

Spcification
ECMAScript 2027 LanguageSpecification
# sec-string.prototype.tostring

Compatibilit des navigateurs

Voir aussi


Web Proxy Viewer  |  New URL  |  Original Page