This section illustrates you the use of JavaScript method charCodeAt(). The charCodeAt() method returns the Unicode of the character at a specified position.
Its syntax is:
| string.charCodeAt(index); |
An Index should be greater than 0 and less than the length of the string. If you will not specified any index value, it will takes the default value 0.Unicode code points range from 0 to 1,114,111. The charCodeAt() will always return a value that is less than 65,536.
Here is the code:
| <html> <script> function charcterCode(){ var st=new String("Welcome to this page"); document.write("The Unicode of the character at position 1 is: "+st.charCodeAt(1)); document.write("<br>"); document.write("The Unicode of the character at position 2 is: "+st.charCodeAt(2)); } </script> <h2>Use of method charCodeAt()</h2> <button onclick="charcterCode();">Character Code</button> </body> </html> |
Output will be displayed as:

On clicking the button you will get the Unicode of the required character:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: JavaScript method charCodeAt()
Post your Comment