Javascript String charCodeAt()

Introduction

We can inspect the character encoding with the charCodeAt() method.

This method returns the code unit value at a given index.

The charCodeAt() method returns an integer between 0 and 65535.

It represents the UTF-16 code unit at the given index.

str.charCodeAt(index)
  • index - an integer greater than or equal to 0 and less than the length of the string.

If index is not a number, it defaults to 0.

let message = "abcde"; 
// Unicode "Latin small letter C" is U+0063 
console.log(message.charCodeAt(2));  // 99 
// Decimal 99 === Hexadecimal 63 
console.log(99 === 0x63);            // true 



PreviousNext

Related