5

A coworker of mine wrote the ES6 line of code...

return map(orderedContentUuids, contentUuid => { uuid: contentUuid });

As you can probably guess he intended to return the object {uuid: contentUuid }, but since its an arrow function, the curly brace { actually starts a new block. (The correct code would be return map(orderedContentUuids, contentUuid => ({ uuid: contentUuid }));).

But, unexpectedly, this code transpiles and runs without an error. There's no error because uuid: contentUuid seems to evaluate to contentUuid.

You can see then that if you put into your JavaScript console foo: 'bar' it evaluates to "bar".

Huh? What's going on. Since when is that valid JS?

0

1 Answer 1

6

Ooops. I just figured it out.

foo: 'bar' is evaluated as a "label", which I did not realize was a JavaScript feature.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label

Sign up to request clarification or add additional context in comments.

1 Comment

Indeed curly braces would not be considered an object in this context.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.