JavaScript: 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
var s = String.fromCodePoint ( 97, 98, 128568 );
console.log ( s === "ab😸" ); // true
// 97 is the code point for letter “a”
// 98 is the code point for letter “b”
// 128568 is the code point for the char 😸 GRINNING CAT FACE WITH SMILING EYES

How to Find Character's Code Point

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

〔►see JavaScript: String.prototype.codePointAt

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

Old Browser Fix

if (!String.fromCodePoint) {
// ES6 Unicode Shims 0.1 , © 2012 Steven Levithan http://slevithan.com/ , MIT License
    String.fromCodePoint = function fromCodePoint () {
        var 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. JavaScript: String is 16-Bit Unit Sequence
  2. JavaScript: Convert Character To/From Codepoint
  3. JavaScript: String.fromCodePoint
  4. JavaScript: String.fromCharCode
  5. JavaScript: String.prototype.charAt
  6. JavaScript: String.prototype.charCodeAt
  7. JavaScript: String.prototype.codePointAt
  8. JavaScript: Convert Decimal/Hexadecimal

String Topic

  1. JavaScript: Default Charset/Encoding
  2. JavaScript: String is 16-Bit Unit Sequence
  3. JavaScript: Unicode Character Escape Sequence
  4. JavaScript: Allowed Characters in Identifier
  5. HTML: Allowed Characters in id Attribute
  6. HTML: Character Sets and Encoding
  7. HTML XML Entities

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

  1. JavaScript: String Object
  2. JavaScript: String.prototype
  3. JavaScript: String Constructor
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.