Join our Newsletter — 33% off our NHI Course
Home› Glossary› Foundations & NHI Taxonomy› fromCharCode()
Foundations & NHI Taxonomy

fromCharCode()

← Back to Glossary
By NHI Mgmt Group Updated November 2, 2026 Domain: Foundations & NHI Taxonomy

fromCharCode() is a string-conversion function used in JavaScript to create text from one or more UTF-16 code units. It does not decode full Unicode code points on its own, so surrogate pairs must be handled separately when building characters outside the Basic Multilingual Plane.

What fromCharCode() Does and Why It Matters

fromCharCode() turns UTF-16 code units into text, which makes it a low-level string-building primitive rather than a full Unicode decoder. That distinction matters because it can create unexpected output if a developer assumes it will safely assemble every character in a modern text stream, especially for symbols outside the Basic Multilingual Plane.

UTF-16 Code Units Versus Unicode Code Points

The function works on code units, so each input value becomes part of the resulting string exactly as provided. For characters that require surrogate pairs, the caller must manage both halves correctly, because fromCharCode() does not interpret the pair as a single code point. In practice, that means the output can be syntactically valid JavaScript text while still being semantically incomplete or misleading.

Common Failure Modes in Real Code

The main failure mode is assuming that numeric character construction is interchangeable with Unicode-aware decoding. That assumption can break international text handling, emoji rendering, and any logic that compares, normalizes, or sanitizes strings. It can also create subtle bugs where visually similar text is built from different underlying code-unit sequences.

Another issue is that developers may use fromCharCode() for obfuscation or dynamic string assembly, which can make code harder to inspect without adding real security. When text is assembled this way, downstream validation still has to treat the final string as ordinary user-controlled or application-generated input.

How It Relates to Safer Text Handling

Modern JavaScript provides Unicode-aware alternatives for code points, and those are usually the better choice when the goal is to construct or interpret full characters rather than raw 16-bit units. The safe pattern is to be explicit about whether you are manipulating code units, code points, or encoded bytes, because each layer answers a different problem.

When the input may include non-ASCII scripts, emoji, or other supplementary characters, text handling should be designed around the character model the application actually needs. If the code mixes byte-level, code-unit-level, and character-level operations, bugs tend to appear at the boundaries rather than in the obvious path.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP ASVS and NIST SP 800-53 Rev 5 set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.

FrameworkControl / ReferenceRelevance
OWASP ASVSV1 — Encoding and SanitizationfromCharCode() affects how text is encoded and assembled from numeric units.
Recommendation — Use Unicode-safe text handling when constructing strings from numeric input.
NIST SP 800-53 Rev 5SI-10 — Information Input ValidationCharacter construction from inputs can alter how downstream validation sees text.
Recommendation — Validate the final string form before it reaches security-sensitive logic.
ISO/IEC 27001:2022A.8.28 — Secure codingThe function is a coding choice that can introduce text-handling defects if misused.
Recommendation — Specify Unicode-safe coding patterns for string construction and parsing.

Practitioner Guidance

Why practitioners should care: fromCharCode() is a precision tool, not a general-purpose Unicode constructor. Use it only when code-unit semantics are intentional, and prefer Unicode-aware APIs when the application needs to preserve characters faithfully across languages and symbols.

What to watch for: any code that builds user-visible text, protocol values, or comparison keys from numeric character inputs deserves a review for surrogate-pair handling, normalization assumptions, and whether a code-point-based API would be clearer.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on November 2, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org