JS Built-ins
StringString.prototype.charAtbeginner

String.prototype.charAt() β€” first character

πŸ“– Usage Example
const str = 'Hello'
str.charAt(0)    // β†’ 'H'
str.charAt(1)    // β†’ 'e'
str.charAt(99)   // β†’ ''

Use charAt() to get the character at a specific index, returning an empty string for out-of-bounds positions.

String.prototype.charAt()

str.charAt(index) returns the character at the specified index, or an empty string '' for out-of-bounds (unlike .at() which returns undefined).

Challenge: Implement firstChar(str) that returns the first character using .charAt(0).

firstChar('hello') // β†’ 'h'
firstChar('world') // β†’ 'w'
πŸ’‘ Hints (1)
  • β€’ `str.charAt(0)` is equivalent to `str[0]` for most cases, but returns `""` instead of `undefined` for out-of-bounds.