JavaScript: String.prototype.charCodeAt

By Xah Lee. Date: . Last updated: .
str.charCodeAt(index)
Return a integer that's the code unit at index index in str. [see Character, Code Unit, Codepoint] To get codepoint, use String.prototype.codePointAt.
console.log( "abc".charCodeAt (0) === 97 ); // true

If the string contains NON-ASCII character, result may not be what you expect.

console.log("😂".charCodeAt(0) === 55357); // true
console.log("😂".charCodeAt(0) === 0xd83d); // true

/* [
😂
name: FACE WITH TEARS OF JOY
codepoint decimal: 128514
codepoint hexadecimal: 1f602
UTF-8 encoding: F0 9F 98 82
UTF-16 encoding: D8 3D DE 02

since the char 😂 in UTF-16 encoding is D8 3D DE 02,
so the first byte in hexadecimal is D83D,
which in decimal is 55357.
therefore its charCode at 0th index is 55357.
] */
∑ JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

String

prototype