Consistency in The Negative Result Values Through Expansion of null's Role
ecmascript at norbertlindenberg.com
Wed Aug 15 21:51:05 PDT 2012
On Aug 15, 2012, at 15:35 , Rick Waldron wrote:
> On Wed, Aug 15, 2012 at 6:02 PM, Erik Reppen <erik.reppen at gmail.com> wrote:
>> * 'wombat'.charAt(20); //returns an empty string, but that's a concrete value whereas 'wombat' returns undefined
> For the same reason indexOf always returns a number, charAt always returns a string.
> "wombat" will dereference the string at an index that doesn't exist, which means it's undefined.
I think undefined would have been a fine return value for 'wombat'.charAt(20) - you asked for something that's not there. The expected return value in the "it's there" case is a one-code-unit string, so an empty string doesn't meet expectations anyway.
It's too late to fix charCodeAt, but for the new codePointAt I'm proposing undefined as the "nothing there" result.
More information about the es-discuss