JavaScript .charCodeAt()
Anonymous contributor
Published Jun 13, 2024
Contribute to Docs
In JavaScript, the .charCodeAt() method, used with strings, returns a positive integer representing the UTF-16 code unit of the character at a specified index in the string. This integer represents the Unicode value of the character.
Syntax
string.charCodeAt(index)
string: The string to be checked.index: The position of the character in the string whose UTF-16 code unit is to be retrieved.
Example
In the following example, a string variable called sentence stores a sentence. Then, the .charCodeAt() method is used to get the Unicode value of a character in the string:
let sentence = 'A sample sentence for demoing how the method works';console.log(sentence.charCodeAt(0));
This results in the following output:
65
Codebyte Example
Here is a codebyte example that demonstrates the usage of the .charCodeAt() method:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours