Using String fromCodePoint() method to coding in Javascript/JS

This JavaScript tutorial explains how to use the string technique called fromCodePoint() with syntax and examples.

Description

In JavaScript, fromCodePoint() is a string technique that is used to create a string from a sequence of Unicode code points (that might also not be representable in a single UTF-16 code unit). Because the fromCodePoint() technique is a static method of the String constructor, it ought to be invoked through the String constructor object as an alternative than through the specific instance of the String class.

Syntax

In JavaScript, the syntax for the fromCodePoint() method is:

String.fromCodePoint(value1, value2, ... value_n);

Parameters or Arguments

value1, value2, … value_n The Unicode code points to convert to characters and then concatenate together into a string.

Returns

The fromCodePoint() approach accepts a sequence of Unicode code points, converts these values to characters and concatenates them collectively in a string. This resulting string is then returned with the aid of the fromCodePoint() method.

The fromCodePoint() method will return RangeError if an invalid code point is furnished as a parameter.

Note

The fromCodePoint() method does no longer trade the fee of the original string. You can also use the fromCharCode() approach if all of the Unicode values are representable in single UTF-16 code units.

Example

Let’s take a seem to be at an example of how to use the fromCodePoint() approach in JavaScript.

For example:

console.log(String.fromCodePoint(134071));

In this example, we have invoked the fromCodePoint() static approach through the String constructor object.

We have written the output of the fromCodePoint() technique to the internet browser console log, for demonstration purposes, to show what the fromCodePoint() method returns.

The following will be output to the internet browser console log:

𠮷

As you can see, the fromCodePoint() method converted the Unicode code point of 134071 into the character value ‘𠮷’.