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?

Mamun
  • 66,969
  • 9
  • 47
  • 59
Chris W.
  • 37,583
  • 36
  • 99
  • 136

1 Answers1

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

Chris W.
  • 37,583
  • 36
  • 99
  • 136