Which built-in object requires keys to be strings or symbols?

The story behind the answer

The built-in object whose keys must be strings or symbols is Object. JavaScript objects store properties as key-value pairs, and each property key is either a string or a Symbol. If another type, such as a number or Boolean, is used as a key, JavaScript converts it to a string.

This rule explains why object indexes can look numeric but are not truly numeric keys: in `({ 7: "x" })`, the property is effectively named "7". Symbols provide a separate key type designed for unique, collision-resistant property names. They are useful when library or framework code needs to attach metadata without accidentally overwriting a normal string-named property.

Object is often compared with Map, but they are different collections. A Map accepts keys of any JavaScript value, including objects, functions, numbers, and booleans, while Object restricts property keys to strings and symbols. WeakMap is narrower still: its keys must be objects or certain non-registered symbols. “Dictionary” is a general data-structure description, not JavaScript’s built-in collection answering this question.

One common surprise is that symbol-keyed properties are skipped by `Object.keys()` and JSON serialization; use `Object.getOwnPropertySymbols()` or `Reflect.ownKeys()` when those keys matter.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: