Creating Objects with Literals
Object literals are the most common way to create objects in JavaScript. An object is a collection of key-value pairs where keys (properties) are strings (or Symbols) and values can be any type, including other objects and functions.
Basic Object Literal Syntax
Wrap key-value pairs in curly braces. Keys can be plain identifiers, quoted strings (required for keys with spaces or hyphens), or computed expressions in square brackets.
Shorthand Properties
When a variable name matches the desired property name, you can use shorthand: instead of { name: name } write simply { name }.
Method Shorthand
Function values in an object can be written with a concise method syntax: { greet() { } } instead of { greet: function() { } }.
Computed Property Names
Square-bracket syntax allows dynamic property names at the time of object creation, which is useful for creating objects from variables or expressions.