Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Property access

Property access uses a dot or square brackets. Dot notation selects a fixed name, while bracket notation evaluates a property key, for example from a variable's value.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

object.property
object[expression]

Property access selects a property of a base value. In object.property, the name property is literal: this notation corresponds to object["property"]. The dot must be followed by a valid IdentifierName; a reserved word is also allowed, as in object.default.

In object[expression], the expression is evaluated. user[key] uses the value of the variable key, whereas user.key looks for a property named "key". Brackets allow names such as "display-name" and keys of type Symbol. To obtain the key, JavaScript first converts the expression's result to a primitive, leaving it unchanged if it is already primitive. If that primitive is a Symbol, it is used directly as the key, including when an object's Symbol.toPrimitive method returns it. Otherwise, the primitive is converted to a string, so object[0] selects the same key as object["0"].

Both forms support reading and, as assignment targets, writing properties. Reading can find an inherited property or invoke a getter. A property absent from an ordinary object and its prototype chain yields undefined; access through null or undefined throws TypeError.

The example reads through a dot, a variable key, and a hyphenated name, then changes the same property through brackets. This is ECMAScript syntax, not a Web API.

Examples

const user = { name: "Ada", "display-name": "Ada L." };
const key = "name";
console.log(user.name);
console.log(user[key]);
console.log(user["display-name"]);
user[key] = "Grace";
console.log(user.name);

Result

Ada
Ada
Ada L.
Grace

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources