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
Let's see some simple examples of charCodeAt() method.
Here, we will print the Unicode value of a character by passing its specific index.Test it Now
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
Here, we will print the Unicode value of last character in a string.Test it Now
Here, we will provide the index number greater than the length of the string. In such case, the method returns NaN.Test it Now