How to create an object?
// object literal
const human = {
name: 'Alice',
age: 21,
someProperty: someValue,
anotherProperty: anotherValue,
someMethod: function() {
// code
},
}
September 3rd, 2019
A Javascript object literal is a comma-separated list of name-value pairs wrapped in curly braces.
Nice extra features:
const obj = { name: name }
is equal const obj = { name }
someMethod: function() {}
becomes someMethod() {}