#92: () => ({ a: 1 })
Topic: scope · Difficulty: ★
const makeObj = () => ({ a: 1 });
console.log(makeObj());Output
{ a: 1 }Why
An arrow function's concise body (no curly braces) implicitly returns whatever expression follows the arrow — but a bare { at the start of that expression is ambiguous, because {} is also how you open a function BODY block. The parser resolves the ambiguity by always treating a leading { as a block, not an object literal. Wrapping the object in parentheses, () => ({ a: 1 }), forces it to be read as a parenthesized expression instead, so it's unambiguously the value being returned. Without the parentheses, () => { a: 1 } would parse as a block containing a label and a stray number, returning undefined.