.fromCodePoint()
The .fromCodePoint()
method returns a string created using the specified sequence of Unicode code points. It allows for the creation of characters from their Unicode values, including characters beyond the Basic Multilingual Plane (code points greater than 0xFFFF
).
This method is commonly used when working with emojis, special symbols, or multilingual characters in applications that require precise Unicode handling such as custom font rendering, text processing, or internationalization.
Syntax
String.fromCodePoint(num1, ..., numN)
Parameters:
num1, ..., numN
: One or more code points.
Return value:
A string formed by the given Unicode code point(s).
Note: If multiple code points are passed, the resulting string will be a concatenation of their corresponding characters.
Example
In this example, multiple Unicode code points are used to create a string containing symbols and a rare character:
console.log(String.fromCodePoint(9731, 9733, 9842, 0x2f804));
The output of the code is:
☃★♲你
This returns a string combining the snowman (☃
), star (★
), recycling symbol (♲
), and a rare CJK character (你
).
Codebyte Example
In this codebyte example, .fromCodePoint()
is used to generate both a single emoji and a string of multiple emojis:
This example shows how .fromCodePoint()
can be used to generate one or more emojis by specifying their Unicode code points.
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours