The charCodeAt(..) function is used to return us the ascii code of a particular character of a String if we supply it with index value.
Say, if we want to know the ASCII code of the letter/character that is present at 2nd index of the String "World".
Assuming the count starts from 0.
<html> <body> <script> var firstString = "World" var pos = firstString.charCodeAt(2) document.write("The ASCII code of the character is : ", pos) </script> </body> </html>
So, in the above code, we have a String World initialised to a variable x.
Then we have used the charCodeAt() Function to get the ASCII code of the letter at index 2.
var pos = firstString.charCodeAt(2)
And as we can see, the letter at index 2 is r. And the ASCII code for r is 114.
So, 114 is taken and put into the variable pos.