Closures returning object literals in Javascript

Let’s assume we have an array of data which we want to process into an array of objects (in Javascript). For instance:

const data = [1, 2, 3, 4, 5, 6];

const squares = data.map((x) => {
  return { number: x, square: x * x };
});

// [{ number: 1, square: 1 },
// { number: 2, square: 4 }, ...]

How do we force the parser to treat the object literal as an Object (without return)? This won’t work, clearly:

data.map((x) => {
  number: x, square: x * x
});
// Syntax error

In order to do this, we simply need to wrap the literal in parenthesis. This forces the parser to treat it as a literal and it works as expected:

data.map((x) => ({ number: x, square: x * x }));
// [{ number: 1, square: 1 },
// { number: 2, square: 4 }, ...]