From 39f2114f9797eb51994966c6bb8ff1814c9a4da8 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:36:08 +0100 Subject: unslug fr: move --- .../global_objects/string/fromcodepoint/index.html | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 files/fr/web/javascript/reference/global_objects/string/fromcodepoint/index.html (limited to 'files/fr/web/javascript/reference/global_objects/string/fromcodepoint') diff --git a/files/fr/web/javascript/reference/global_objects/string/fromcodepoint/index.html b/files/fr/web/javascript/reference/global_objects/string/fromcodepoint/index.html new file mode 100644 index 0000000000..387ecf4878 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/string/fromcodepoint/index.html @@ -0,0 +1,111 @@ +--- +title: String.fromCodePoint() +slug: Web/JavaScript/Reference/Objets_globaux/String/fromCodePoint +tags: + - ECMAScript 2015 + - JavaScript + - Méthode + - Reference + - String + - polyfill +translation_of: Web/JavaScript/Reference/Global_Objects/String/fromCodePoint +--- +
{{JSRef}}
+ +

La méthode statique String.fromCodePoint() renvoie une chaîne de caractères créée à partir d'un suite de codets.

+ +
{{EmbedInteractiveExample("pages/js/string-fromcodepoint.html")}}
+ + + +

Syntaxe

+ +
String.fromCodePoint(num1[, ...[, numN]])
+ +

Paramètres

+ +
+
num1, ..., numN
+
Une séquence de codets (code points).
+
+ +

Valeur de retour

+ +

Une chaîne de caractères créée à partir de la séquence de codets indiquée.

+ +

Exceptions

+ + + +

Description

+ +

fromCodePoint() étant une méthode statique de {{jsxref("String")}}, elle doit toujours être utilisée avec la syntaxe String.fromCodePoint(), plutôt qu'avec une méthode d'un objet {{jsxref("String")}} qui aurait été créé.

+ +

Exemples

+ +

Utiliser fromCodePoint()

+ +
String.fromCodePoint(42);       // "*"
+String.fromCodePoint(65, 90);   // "AZ"
+String.fromCodePoint(0x404);    // "\u0404"
+String.fromCodePoint(0x2F804);  // "\uD87E\uDC04"
+String.fromCodePoint(194564);   // "\uD87E\uDC04"
+String.fromCodePoint(0x1D306, 0x61, 0x1D307) // "\uD834\uDF06a\uD834\uDF07"
+
+String.fromCodePoint('_');      // RangeError
+String.fromCodePoint(Infinity); // RangeError
+String.fromCodePoint(-1);       // RangeError
+String.fromCodePoint(3.14);     // RangeError
+String.fromCodePoint(3e-2);     // RangeError
+String.fromCodePoint(NaN);      // RangeError
+
+ +

Comparaison avec fromCharCode()

+ +

La méthode {{jsxref("String.fromCharCode()")}} ne peut pas renvoyer les caractères de l'intervalle 0x010000 à 0X10FFFF avec un seul codet, il est nécessaire de lui fournir la paire décomposée (surrogate pair) pour obtenr un tel caractère :

+ +
String.fromCharCode(0xD83C, 0xDF03); // émoji « nuit étoilée »
+String.fromCharCode(55356, 57091);   // équivalent en notation décimale
+ +

String.fromCodePoint(), en revanche, peut renvoyer les caractères qui s'expriment sur plus d'un codet de 16 bits grâce à leur codet « simple » :

+ +
String.fromCodePoint(0x1F303); // ou 127747 en notation décimale
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-string.fromcodepoint', 'String.fromCodePoint')}}{{Spec2('ES2015')}}Définition initiale
{{SpecName('ESDraft', '#sec-string.fromcodepoint', 'String.fromCodePoint')}}{{Spec2('ESDraft')}}
+ +

Compatibilité des navigateurs

+ + + +

{{Compat("javascript.builtins.String.fromCodePoint")}}

+ +

Voir aussi

+ + -- cgit v1.2.3-54-g00ecf