3 Example(s) of JavaScript charCodeAt function


Description :

charCodeAt-1


JavaScript charCodeAt function Example - 1
<!DOCTYPE html>
<html>
 <head>
    <title>Welcome to LearnKode - A code learning platform</title>
</head>
  <body>
 <button onclick="findUnicode()">Display the unicode</button>
<p id="sample"></p>
<script>
function findUnicode() {
    var str = "HELLO WORLD";
    var n = str.charCodeAt(0);
    document.getElementById("sample").innerHTML = n;
}
</script>

      </body>
</html>

Output

Description :

charCodeAt-2


JavaScript charCodeAt function Example - 2
<!DOCTYPE html>
<html>
 <head>
    <title>Welcome to LearnKode - A code learning platform</title>
</head>
  <body>
 <button onclick="findUnicode()">Display the unicode</button>
<p id="sample"></p>
<script>
function findUnicode() {
     var str = "HELLO WORLD";
    var n = str.charCodeAt(str.length-1);
    document.getElementById("sample").innerHTML = n;
}
</script>
      </body>
</html>

Output

Description :

charCodeAt-3


JavaScript charCodeAt function Example - 3
<!DOCTYPE html>
<html>
 <head>
    <title>Welcome to LearnKode - A code learning platform</title>
</head>
  <body>
 <button onclick="findUnicode()">Display the unicode</button>
<p id="sample"></p>
<script>
function findUnicode() {
        document.getElementById("sample").innerHTML = 'ABC'.charCodeAt(0);
}
</script>

      </body>
</html>

Output