I apologize for posting a duplicate-looking question, (I know, that there is a bunch of similar titled questions here), but none of the questions already present seems to suit m
If you'd have read further down the page you linked, you would see why it was written like that.
var func = () => { foo: 1 };
This is an attempt to return an object from a arrow function.
That doesn't work for reasons explained here:
This is because the code inside braces (
{}
) is parsed as a sequence of statements (i.e.foo
is treated like a label, not a key in an object literal). (source)
So the returned value needs to be wrapped in parentheses:
var func = () => ({foo: 1});
To actually answer your question:
You can't just take the foo: 1
out of context like that.