Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1028698 of RangeError: argument is not a valid code point

  • Revision slug: Web/JavaScript/Reference/Errors/Not_a_codepoint
  • Revision title: Not a codepoint
  • Revision id: 1028698
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment new page

Revision Content

{{jsSidebar("Errors")}}

Message

RangeError: {0} is not a valid code point (Firefox)
RangeError: Invalid code point {0} (Chrome)

Error type

{{jsxref("RangeError")}}

What went wrong?

You were using the {{jsxref("String.fromCodePoint()")}} method which only accepts valid code points. A code point is a value in the Unicode codespace; that is, the range of integers from 0 to 0x10FFFF. You cannot use {{jsxref("NaN")}} values, negative Integers (-1), non-Integers (3.14), or values larger than 0x10FFFF (1114111) with this method.

Examples

Invalid cases

String.fromCodePoint('_');      // RangeError
String.fromCodePoint(Infinity); // RangeError
String.fromCodePoint(-1);       // RangeError
String.fromCodePoint(3.14);     // RangeError
String.fromCodePoint(3e-2);     // RangeError
String.fromCodePoint(NaN);      // RangeError

Valid cases

String.fromCodePoint(42);       // "*"
String.fromCodePoint(65, 90);   // "AZ"
String.fromCodePoint(0x404);    // "\u0404"
String.fromCodePoint(0x2F804);  // "\uD87E\uDC04"
String.fromCodePoint(194564);   // "\uD87E\uDC04"
String.fromCodePoint(0x1D306, 0x61, 0x1D307) // "\uD834\uDF06a\uD834\uDF07"

See also

  • {{jsxref("String.fromCodePoint()")}}

Revision Source

<div>{{jsSidebar("Errors")}}</div>

<h2 id="Message">Message</h2>

<pre class="syntaxbox">
RangeError: {0} is not a valid code point (Firefox)
RangeError: Invalid code point {0} (Chrome)
</pre>

<h2 id="Error_type">Error type</h2>

<p>{{jsxref("RangeError")}}</p>

<h2 id="What_went_wrong">What went wrong?</h2>

<p>You were using the {{jsxref("String.fromCodePoint()")}} method which only accepts valid code points. A <a href="https://en.wikipedia.org/wiki/Code_point">code point</a> is a value in the Unicode codespace; that is, the range of integers from <code>0</code> to <code>0x10FFFF</code>. You cannot use {{jsxref("NaN")}} values, negative Integers (<code>-1</code>), non-Integers (<code>3.14</code>), or values larger than&nbsp;<code>0x10FFFF</code> (<code>1114111</code>) with this method.</p>

<h2 id="Examples">Examples</h2>

<h3 id="Invalid_cases">Invalid cases</h3>

<pre class="brush: js example-bad">
String.fromCodePoint('_');      // RangeError
String.fromCodePoint(Infinity); // RangeError
String.fromCodePoint(-1);       // RangeError
String.fromCodePoint(3.14);     // RangeError
String.fromCodePoint(3e-2);     // RangeError
String.fromCodePoint(NaN);      // RangeError</pre>

<h3 id="Valid_cases">Valid cases</h3>

<pre class="brush: js example-good">
String.fromCodePoint(42);       // "*"
String.fromCodePoint(65, 90);   // "AZ"
String.fromCodePoint(0x404);    // "\u0404"
String.fromCodePoint(0x2F804);  // "\uD87E\uDC04"
String.fromCodePoint(194564);   // "\uD87E\uDC04"
String.fromCodePoint(0x1D306, 0x61, 0x1D307) // "\uD834\uDF06a\uD834\uDF07"
</pre>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("String.fromCodePoint()")}}</li>
</ul>
Revert to this revision