Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026
The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.
JavaScript provides several ways to access individual characters in a string.
charAt()
Returns the character at the specified index:
'Flavio'.charAt(0) //'F'
'Flavio'.charAt(1) //'l'
'Flavio'.charAt(2) //'a'
If you give an index that doesn’t match the string, you get an empty string.
JavaScript doesn’t have a “char” type, so a char is a string of length 1.
Bracket Notation
You can also use bracket notation to access characters (not supported in older IE versions):
'Flavio'[0] //'F'
'Flavio'[1] //'l'
charCodeAt()
Returns the Unicode 16-bit integer representing the character at the specified index:
'Flavio'.charCodeAt(0) //70
'Flavio'.charCodeAt(1) //108
'Flavio'.charCodeAt(2) //97
Calling toString(16) after that returns the hexadecimal value, which you can look up in Unicode tables.
codePointAt()
Introduced in ES2015 to handle Unicode characters that cannot be represented by a single 16-bit Unicode unit.
Using charCodeAt() with characters that need 2 UTF-16 units requires retrieving both and combining them. codePointAt() gets the whole character in one call.
For example, this Chinese character ”𠮷” is composed of 2 UTF-16 parts:
"𠮷".charCodeAt(0).toString(16) //d842
"𠮷".charCodeAt(1).toString(16) //dfb7
If you create a new character by combining those Unicode characters:
"\ud842\udfb7" //"𠮷"
You can get the same result using codePointAt():
"𠮷".codePointAt(0) //20bb7
And create the character using the Unicode code point:
"\u{20bb7}" //"𠮷"