Example 1 — Positive Indexes
Read the first and fifth characters with charAt(0) and charAt(4).
const text = "Hello";
console.log(text.charAt(0)); // "H"
console.log(text.charAt(4)); // "o" How It Works
- Build the string.
"Hello"has indexes0…4. - Read the first slot.
charAt(0)returns"H"— same idea astext[0]. - Read the last slot.
charAt(4)lands on"o". - No side effects. The string is unchanged;
charAtonly reads.

