Using 'undefined' as a key in an object causes the use of <undefined `as a key. What for?

As in, {'undefined': 'foo'}leads to {undefined: 'foo'}.

In Chrome:

Chrome Screenshot

In Firefox:

Firefox screenshots

In Safari:

Safari screenshots

Why? I tried other reserved words (such as nulland true) and they are also converted.

+4
source share
1 answer

This has nothing to do with reserved words. Object keys are displayed in this way, regardless of which line you use for the key. This is just how it is interpreted / presented to you on the console.

var o = {'cheese': 'foo'};
// Object {cheese: "foo"}

o.cheese; // "foo"
o['cheese']; // "foo"

Quotation marks are not needed for access, so they are removed.

+3
source

Source: https://habr.com/ru/post/1570225/


All Articles