Chaîne JavaScript deCodePoint ()

La méthode JavaScript String fromCodePoint () renvoie une chaîne créée à l'aide de la séquence de points de code donnée.

La syntaxe de la fromCodePoint()méthode est:

 String.fromCodePoint(num1,… , numN)

La fromCodePoint()méthode, étant une méthode statique, est appelée en utilisant le Stringnom de la classe.

Paramètres fromCodePoint ()

La fromCodePoint()méthode prend en compte:

  • num1,…, numN - Une séquence de points de code.

Valeur renvoyée par fromCodePoint ()

  • Renvoie une chaîne créée à l'aide de la séquence spécifiée de points de code.

Remarques :

  • La fromCodePoint()méthode renvoie un RangeErrorsi un point de code Unicode non valide est donné.
  • La fromCodePoint()méthode renvoie une chaîne et non un Stringobjet.

Exemple: Utilisation de la méthode fromCodePoint ()

 let string1 = String.fromCodePoint(65, 66, 67); console.log(string1); // ABC let string2 = String.fromCharCode(72, 69, 76, 76, 79); console.log(string2); // HELLO // numbers can be passed as hexadecimals let string3 = String.fromCodePoint(0x2f804); console.log(string3); // "uD87EuDC04" // unlike fromCharCode() that requires surrogate pair to return supplementary char // fromCodePoint() can even return 4-byte supplementary chars let string4 = String.fromCodePoint(0x1f303); console.log(string4); // Unicode character "Night with Stars" let string5 = String.fromCodePoint(Infinity); console.log(string5); // RangeError

Production

 ABC HELLO uD87E uDC04 RangeError: Point de code non valide Infinity

Lecture recommandée: JavaScript String fromCharCode ()

Articles intéressants...