JavaScript String charAt() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

String.prototype.charAt(index) returns one UTF-16 code unit as a string at a zero-based index. Out of range returns "". It is read-only, widely supported, and never mutates the string.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call string.charAt. Start with this line.

JavaScript
string.charAt(index)
CallWhat it does
string.charAt(index)Primary signature.
string.charAt(...)Call with the arguments your case needs.

Built into JavaScript. Call charAt(...) on a string (or String instance) — no import required.

Library declarations
JavaScript
string.charAt(index)

Parameters

ParameterDescription
indexRequired. Zero-based position (negatives → "")
Empty-string checkOptional. Needed when missing characters matter

Return Value

Return ValueDescription
*The value returned by string.charAt().

JavaScript Examples

Example 1 — Positive Indexes

Read the first and fifth characters with charAt(0) and charAt(4).

JavaScript
const text = "Hello";

console.log(text.charAt(0));  // "H"
console.log(text.charAt(4));  // "o"
Try It Yourself

How It Works

  1. Build the string. "Hello" has indexes 0 … 4.
  2. Read the first slot. charAt(0) returns "H" — same idea as text[0].
  3. Read the last slot. charAt(4) lands on "o".
  4. No side effects. The string is unchanged; charAt only reads.

Example 2 — Out of Range Returns ""

Missing indexes return an empty string — not undefined.

JavaScript
const text = "Hello";

console.log(JSON.stringify(text.charAt(5)));   // ""
console.log(JSON.stringify(text.charAt(-1)));  // ""
console.log(text.charAt(text.length - 1));     // "o"
Try It Yourself

How It Works

  1. Past the end. Index 5 is outside 0…4 → "".
  2. Negatives fail. charAt(-1) is also out of range → "".
  3. Last the classic way. length - 1 is the pre-at() pattern for the last character.
  4. Why it matters. Check for "", not undefined, when using charAt.

Example 3 — charAt() vs at() vs Brackets

Same index often matches; negatives and out-of-range results differ.

JavaScript
const text = "Hello";

console.log(text.charAt(1));  // "e"
console.log(text.at(1));      // "e"
console.log(text[1]);         // "e"

console.log(JSON.stringify(text.charAt(10))); // ""
console.log(text.at(10));                     // undefined
console.log(text[10]);                        // undefined

console.log(JSON.stringify(text.charAt(-1))); // ""
console.log(text.at(-1));                     // "o"
Try It Yourself

How It Works

  1. Valid indexes match. charAt(1), at(1), and text[1] all return "e".
  2. Missing slots differ. charAt → ""; at and brackets → undefined.
  3. Negatives only work with at. charAt(-1) is ""; at(-1) is the last character.
  4. Rule of thumb. Need last-character access? Prefer at(-1).

Browser & Runtime Support

String.prototype.charAt() is Baseline Widely available — supported in every modern browser and legacy environments for decades.

✓ Baseline · Widely available

String.prototype.charAt()

Supported in all evergreen browsers, Internet Explorer, and every current Node.js / Deno / Bun release. Safer for old targets than at().

100% Universal support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 4+ · Legacy environments
Full support
Opera All modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
String.charAt() Universal

Bottom line: Safe everywhere, including IE. Prefer at(-1) when you need last-character access in modern code; keep charAt when you want "" for missing indexes or must support very old engines.

Frequently Asked Questions

charAt(index) returns a one-character string at that zero-based index (one UTF-16 code unit). If the index is out of range, it returns an empty string "" — it never throws.
No. charAt(-1) returns "". To read from the end, use at(-1) or charAt(str.length - 1).
at() supports negative indexes and returns undefined when out of range. charAt() does not support negatives and returns "" for out-of-range indexes.
charAt() always returns a string ("" when missing). Bracket notation returns undefined for a missing index. Both use zero-based positions for valid indexes.
Not always. charAt() returns one UTF-16 code unit. Many emoji use two code units (a surrogate pair). Prefer codePointAt() or [...str] for full code points.
No. Strings are immutable. charAt() returns a new one-character string (or "").

Next: charCodeAt()

Learn how to read the UTF-16 numeric code unit at a string index.

charCodeAt() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful