A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint below:

String.fromCodePoint() - JavaScript | MDN

String.fromCodePoint()

Baseline Widely available

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

Exemple interactif
console.log(String.fromCodePoint(9731, 9733, 9842, 0x2f804));
// Expected output: "☃★♲你"
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 String, elle doit toujours être utilisée avec la syntaxe String.fromCodePoint(), plutôt qu'avec une méthode d'un objet 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 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 Compatibilité des navigateurs Voir aussi

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4