Skip to content

JavaScript char to int | Example code

  • by

Convert char to int using charCodeAt method in JavaScript. Take first char of the string to convert to an ASCII code.

String.charCodeAt(0);

Complete code

<!DOCTYPE html>
<html>
<body>

  <script>

    alert("A".charCodeAt(0);)
  </script>
</body>
</html>

Output:

JavaScript char to int

Another example


var chr ='A';
chr.charCodeAt(0); //65

Do comment if you have another example or suggestions or doubts on this JS char topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading