65535 representing the UTF-16 code unit at the given index.
Note: If index is out of range, charCodeAt() returns NaN.
The following example returns
65, the Unicode value for A.
'ABC'.charCodeAt(0) // returns 65
Simple example code get the Unicode of the first character in a string. Where index of the first character is 0, the second is 1.
<!DOCTYPE html> <html> <body> <script> let text = "HELLO WORLD"; let code = text.charCodeAt(0); console.log(code) </script> </body> </html>
Get the Unicode of the last character in a string:
<script> let text = "HELLO WORLD"; let code = text.charCodeAt(text.length-1); console.log(code) </script>
Do comment if you have any doubt or suggestions on this JS basic function.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.