svenema
svenema

Reputation: 2516

What does/could this Javascript notation { e => e } signify?

While troubleshooting a pdf-lib issue, I'm seeing this, to me unfamiliar, notation:

{ e => e }

Screenshot:

enter image description here

Upvotes: 1

Views: 77

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074305

What does/could this Javascript notation { e => e } signify?

It isn't JavaScript notation (e.g., syntax) in that context.¹ The display of objects in a console is not JavaScript syntax, though it's often closely related to it. That {e => e} (and {e => t} later) is just Chrome's console's way of showing you a Map entry where the key is an object whose constructor function is e and whose value is an object whose constructor function is also e (or t for the { e => t } case).

You can see that here (in Chrome or others that use a similar display):

class e {
}
const m = new Map();
m.set(new e(), new e());
console.log(m);
Look in the real JavaScript console.

The real code presumably used a more meaningful constructor names than e and t, but has been minified.


¹ If { e => e} appeared in JavaScript code where a statement was expected, it would be a block with an arrow function inside it that could never be called; if it appeared where an expression rather than a statement was expected, it'd be a syntax error.

Upvotes: 6

Related Questions