1

I recently came across code like this:

if (!validate(event)) {
    logger.error('Invalid message: validation failed', { event })
}

which got me wondering, what's it called when you enclose an object in an object literal like { event }, which appears to just give you a new object that looks like:

let event = { "a": 1, "b": 2 }

console.log({ event })
// { event: { a: 1, b: 2 } }

Why does this work this way / what is it called?

UnknownBeef
  • 418
  • 3
  • 17

1 Answers1

-1

It is called object construction - as appose to object deconstruction

Yogev D.
  • 118
  • 4