EN
JavaScript - String charCodeAt() method example
5 points
xxxxxxxxxx
1
var text = 'abc';
2
console.log( text.charCodeAt(0) ); // 97
3
4
console.log( 'abc'.charCodeAt(0) ); // 97
5
console.log( 'abc'.charCodeAt(1) ); // 98
6
console.log( 'abc'.charCodeAt(2) ); // 99
7
8
console.log( text.charCodeAt() ); // 97
9
console.log( text.charCodeAt(-1) ); // NaN
10
console.log( text.charCodeAt(10) ); // NaN
11
console.log( text.charCodeAt(null) ); // 97
Syntax | String.prototype.charCodeAt(index) |
Parameters | index - integer number value that represents character position (primitive value). |
Result | Character code from index position (primitive value). |
Description | charCodeAt 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. |