The Object Literal { }
Definition
{ } is the literal syntax to initialize an object.
While it is technically a literal syntax rather than an operator, it is how objects are structured.
Note
In JavaScript, the { } symbol serves different purposes depending on how it is used:
Bundle code inside if statements:
if (true) {
// bundled code lines
}
Bundle code inside loops:
for (let i=0; i<10; i++) {
// bundled code lines
}
Limit visability (scope):
{
// standalone code
}
Object literal syntax:
const user = { name: "Alice", age: 25 };
Object destructuring:
const { name, id } = person;
Named imports and exports:
import { useState, useEffect } from "react";
Browser Support
{ } is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |