'Object literal with single identifier inside [duplicate]

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?



Solution 1:[1]

It is called object construction - as appose to object deconstruction

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yogev D.