JavaScript String.fromCodePoint()
Syntax & Examples
Syntax of String.fromCodePoint()
The syntax of String.fromCodePoint() static-method is:
String.fromCodePoint()
String.fromCodePoint(num1)
String.fromCodePoint(num1, num2)
String.fromCodePoint(num1, num2, /* …, */ numN)
This fromCodePoint() static-method of String returns a string created by using the specified sequence of code points.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
num1 | required | The first code point value. |
num2 | optional | Additional code point values. |
Return Type
String.fromCodePoint() returns value of type string
.
✐ Examples
1 String from code points 65, 66, and 67
In this example,
We call String.fromCodePoint
with the code points 65, 66, and 67 which correspond to the characters 'A', 'B', and 'C' respectively.
JavaScript Program
console.log(String.fromCodePoint(65, 66, 67));
Output
ABC
2 String from various code points including emoji and non-BMP characters
In this example,
We call String.fromCodePoint
with various code points including emoji and non-BMP characters.
JavaScript Program
console.log(String.fromCodePoint(9731, 9733, 9842, 0x2F804));
Output
☃★♲你
3 String from code point 0x1F680 (Rocket emoji)
In this example,
We call String.fromCodePoint
with the code point 0x1F680 which corresponds to the rocket emoji.
JavaScript Program
console.log(String.fromCodePoint(0x1F680));
Output
🚀
Summary
In this JavaScript tutorial, we learned about fromCodePoint() static-method of String: the syntax and few working examples with output and detailed explanation for each example.