JS: String.fromCodePoint

By Xah Lee. Date: . Last updated: .

New in ES2015.

String.fromCodePoint ( codePoint1, codePoint2 … )

Returns a string, each character corresponds to the code point in argument.

// convert sequence of unicode code point to string

console.log (
 String.fromCodePoint ( 97, 128514 ) === "a😂"
);
// true

// 97 is the code point for letter “a”
// 128514 is the code point for the char 😂 FACE WITH TEARS OF JOY

How to Find Character's Code Point

To find character's code point, use String.prototype.codePointAt.

〔►see JS: String.prototype.codePointAt

For code point of English character and punctuations, see ASCII Table.

fromCodePoint polyfill

if (!String.fromCodePoint) {
// ES6 Unicode Shims 0.1 , © 2012 Steven Levithan http://slevithan.com/ , MIT License
    String.fromCodePoint = function fromCodePoint () {
        let chars = [], point, offset, units, i
        for (i = 0; i < arguments.length; ++i) {
            point = arguments[i]
            offset = point - 0x10000
            units = point > 0xFFFF ? [0xD800 + (offset >> 10), 0xDC00 + (offset & 0x3FF)] : [point]
            chars.push(String.fromCharCode.apply(null, units))
        }
        return chars.join("")
    }
}

Reference

ECMAScript 2015 §Text Processing#sec-string.fromcodepoint

Character Topic

  1. JS: String Code Unit vs Code Point
  2. JS: Convert Character To/From Codepoint
  3. JS: String.fromCodePoint
  4. JS: String.fromCharCode
  5. JS: String.prototype.charAt
  6. JS: String.prototype.charCodeAt
  7. JS: String.prototype.codePointAt
  8. JS: Convert Decimal/Hexadecimal
  9. JS: Unicode Character Escape Sequence

String Topic

  1. JS: Default Charset/Encoding
  2. JS: String Code Unit vs Code Point
  3. JS: Unicode Character Escape Sequence
  4. JS: Allowed Characters in Identifier
  5. HTML: Allowed Characters in id Attribute
  6. HTML: Character Sets and Encoding
  7. HTML/XML Entity List

  1. JS: Template String
  2. JS: Convert String to Number
  3. JS: Encode URL, Escape String
  4. JS: Format Number
  5. JS: JSON Object

  1. JS: String Object
  2. JS: String.prototype
  3. JS: String Constructor
Like what you read? Buy JavaScript in Depth