1var myVar='A';
2var myVarAscii = myVar.charCodeAt(0); //convert 'A' character to it's ASCII code (65)
1/*
2charAt() method
3This method takes in a string and an index as input
4and returns the character at that position in the specified string
5*/
6
7myString = "Hello World!";
8
9console.log(myString.charAt(0)); // outputs "H"
10console.log(myString.charAt(5)); // outputs " "
11console.log(myString.charAt(8)); // outputs "r"
12// If the specified index is bigger or equal to the length of the string,
13// the output will be "".
14console.log(myString.charAt(23)); // outputs ""
1const sentence = 'The quick brown fox jumps over the lazy dog.';
2
3const index = 4;
4
5console.log(`The character code ${sentence.charCodeAt(index)} is equal to ${sentence.charAt(index)}`);
6// expected output: "The character code 113 is equal to q"
7
1const sentence = 'The quick brown fox jumps over the lazy dog.';
2
3const index = 4;
4// return the chartcode of the character with index N°4
5const charcode= sentence.charCodeAt(index);
6console.log (charcode);
7// expected output: "The character code 113 is equal to q"
8
9// remember that charCodeAt return the code on ♦ keypress event ♦