JS Built-ins
StringString.prototype.charCodeAtbeginner

String.prototype.charCodeAt() β€” code for A

πŸ“– Usage Example
const str = 'ABC'
str.charCodeAt(0)   // β†’ 65
str.charCodeAt(1)   // β†’ 66
str.charCodeAt(99)  // β†’ NaN

Use charCodeAt() to get the UTF-16 code unit value of the character at the given index.

String.prototype.charCodeAt()

str.charCodeAt(index) returns the UTF-16 code unit value of the character at the given index, or NaN for out-of-bounds.

Challenge: Implement getCode(str, i) that returns the char code at index i.

getCode('A', 0) // β†’ 65
getCode('a', 0) // β†’ 97
πŸ’‘ Hints (1)
  • β€’ ASCII: A=65, Z=90, a=97, z=122, 0=48, 9=57, space=32.