Javatpoint Logo
Javatpoint Logo

JavaScript String charCodeAt() Method

The JavaScript string charCodeAt() method is used to find out the Unicode value of a character at the specific index in a string.

The index number starts from 0 and goes to n-1, where n is the length of the string. It returns NaN if the given index number is either a negative number or it is greater than or equal to the length of the string.


The charCodeAt() method is represented by the following syntax:


index - It represent the position of a character.


A Unicode value

JavaScript String charCodeAt() Method Example

Let's see some simple examples of charCodeAt() method.

Example 1

Here, we will print the Unicode value of a character by passing its specific index.

Test it Now



Example 2

In this example, we will not pass any index number with the method. In such case, it will return the Unicode value of first character.

Test it Now



Example 3

Here, we will print the Unicode value of last character in a string.

Test it Now



Example 4

Here, we will provide the index number greater than the length of the string. In such case, the method returns NaN.

Test it Now



Next TopicJavaScript String

Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA