What does console.log('abc'.at(-1), 'abc'.at(5)) output?
A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-81.js
1console.log('abc'.at(-1),'abc'.at(5))
Coercion
Answer & explanation
Console output
c undefined
Why
at(-1) returns the last character "c" by counting from the end. When the index is out of range, like at(5) on a 3-character string, at returns undefined rather than "". This differs from charAt, which returns "" for out-of-range indices. That is another reason at behaves more predictably.