JS Built-ins
StringString.prototype.atintermediate

String.prototype.at() β€” out-of-bounds returns undefined

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

Use at() to access a character by index, supporting negative indices to count from the end.

String.prototype.at() β€” Out-of-Bounds

Both positive out-of-bounds and very negative indices return undefined.

Challenge: Implement safeAt(str, i) that uses .at(i) and returns '?' if the result is undefined.

safeAt('hi', 0)  // β†’ 'h'
safeAt('hi', 99) // β†’ '?'
πŸ’‘ Hints (1)
  • β€’ Use the nullish coalescing operator `??` to provide a fallback.