• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Actual Wizard

Actual Wizard

Great Content From Actual Wizards

  • Blogging
  • Programming
  • Social Media
  • Marketing
You are here: Home / Programming / JavaScript

JavaScript String fromCodePoint Method Explained

August 23, 2020 by Kevin Marszalek

The fromCodePoint() method allows JavaScript to create a string from a sequence of UTF-16 or UTF-32 character codes and is useful for dealing with characters that are difficult to type or need to be escaped.

String.fromCodePoint()

Note: This method is a static method of the object named string and is not an inherited method of a variable that is a string. If you attempt to call the method as if it were a descendant of the string object, you will generate the following error:

fromCodePoint is not a function

The following code example is a simple demonstration of the fromCodePoint() method:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
	<meta content="utf-8" http-equiv="encoding">
	<title>JavaScript String fromCodePoint Method Example</title>
</head>
<body>
<script>
	var MyText = "abc";
	MyText += String.fromCodePoint(49,50,51);
	console.log(MyText);
</script>
</body>
</html>

The following text is printed to the console:

abc123

Valid Character Input Types for fromCodePoint()

This method will accept character formatted three different ways:

Note: Each example will produce the word “HELLO.”

Decimals:

MyString = String.fromCodePoint(72,69,76,76,79,46);

Hex Values:

MyString = String.fromCodePoint(0x48,0x45,0x4c,0x4c,0x4f,0x2e);

Octal Values:

MyString = String.fromCodePoint(0o110,0o105,0o114,0o114,0o117,0o56);

Limitations of fromCodePoint()

This method will not work correctly with escaped Unicode characters and if you attempt to you will generate the following error message:

Uncaught RangeError: NaN is not a valid code point

Instead a string can be assigned an escaped Unicode sequence as follows:

var MyString = '\u0048\u0045\u004C\u004C\u004F\u002E';
//HELLO.

Difference of fromCodePoint() and fromCharCode()

The fromCodePoint() method should work with all valid UTF-32 values and it is recommended over fromCharCode() in almost all circumstances.

If the code provided to this method is outside of the range of valid UTF-32 values, the following error message will be generated:

Uncaught RangeError: "The Value" is not a valid code point

Filed Under: JavaScript

Read More From Actual Wizard

  • Understanding the Different Parts of an Email Address
    An email address has four parts; the recipient name, the @ symbol, the domain name, and the top-level domain. …
  • How to Get the Last Element of an Array in JavaScript
    There are a number of different ways to get the last element of an array in JavaScript. Below we will explore …
  • How to use document.write() in JavaScript
    How to use document.write() in JavaScript The document.write() function is commonly used when testing simple …
  • How to Open a New Tab with JavaScript
    Opening a new browser window in a new tab can be done easily in JavaScript. Modern web browsers provide a …

Primary Sidebar

More posts from this section

  • How to Get the Last Element of an Array in JavaScript
  • How to use document.write() in JavaScript
  • How to Open a New Tab with JavaScript
  • How to Convert an HTML Node to a String in JavaScript
  • JavaScript String Anchor Method Explained
  • JavaScript String Big Method Explained
  • JavaScript String Blink Method Explained
  • JavaScript String Bold Method Explained
  • JavaScript String charAt Method Explained
  • JavaScript String charCodeAt Method Explained

Copyright © 2025 ActualWizard.com

  • About
  • Terms of Service
  • Privacy Policy
  • Cookie Policy