Dot notation reads a property whose name is a valid identifier, while bracket notation takes any string or a variable as the key.
Use dot notation, as in obj.name, whenever the key is fixed and a valid identifier. It is shorter and easier to read. Use bracket notation, as in obj["full name"], when the key has spaces or special characters. A key that starts with a digit needs it too.
Brackets also take an expression, so obj[key] reads whatever property the variable key names at runtime. That makes bracket notation the only choice for dynamic keys, such as when looping over property names.
const obj = { name: "John", "full name": "John Doe" };
obj.name; // Dot notation
obj["full name"]; // Bracket notation
obj[variable]; // Dynamic access
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓