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?