JavaScript - String charCodeAt() method example

5 points
Created by:
// ONLINE-RUNNER:browser;

var text = 'abc';
console.log( text.charCodeAt(0) ); // 97

console.log( 'abc'.charCodeAt(0) ); // 97
console.log( 'abc'.charCodeAt(1) ); // 98
console.log( 'abc'.charCodeAt(2) ); // 99

console.log( text.charCodeAt()     ); // 97
console.log( text.charCodeAt(-1)   ); // NaN
console.log( text.charCodeAt(10)   ); // NaN
console.log( text.charCodeAt(null) ); // 97

1. Documentation

Parametersindex - integer number value that represents character position (primitive value).
ResultCharacter code from index position (primitive value).
DescriptioncharCodeAt takes only one parameter and return character code at index position inside string. The codes are compatible with UTF-16 (Unicode). If some character code is bigger than 0xFFFF then retuened is first part of code. For index from out of range NaN is returned.

Alternative titles

  1. JavaScript - String.prototype.charCodeAt() documentation with examples
  2. js - String charCodeAt() method documentation with examples
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - String (documentation)

Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂