> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript Computed Member Access

The `[]` (bracket) operator is a member access operator that evaluates to a Reference Record used to resolve a property on an object. Unlike dot notation, bracket notation evaluates the expression provided within the brackets and coercively resolves the resulting value into a string or a `Symbol` to determine the property key.

## Syntax

```javascript theme={"dark"}
object[expression]
```

## Evaluation Mechanics

When the JavaScript engine encounters the `[]` operator, it follows a strict sequence defined by the ECMAScript specification. Crucially, the operator itself does not read, write, or delete values; it strictly returns a Reference Record. The surrounding syntax (such as an assignment operator, standard read, or the `delete` keyword) dictates whether an internal `[[Get]]`, `[[Set]]`, or `[[Delete]]` method is subsequently called on that Reference.

The evaluation order is as follows:

1. **Base Evaluation:** The `object` expression to the left of the brackets is evaluated to retrieve the base value.
2. **Expression Evaluation:** The `expression` inside the brackets is evaluated to retrieve the property name value.
3. **Coercibility Check (`RequireObjectCoercible`):** The engine checks if the base value is object-coercible. If the base evaluates to `null` or `undefined`, a `TypeError` is thrown. Because this check occurs *after* the bracket expression is evaluated but *before* key coercion, side effects from evaluating the expression itself will occur, but side effects from key coercion (such as invoking a custom `toString()` method on an object) will not execute.
4. **Key Coercion (`ToPropertyKey`):** The engine applies the internal `ToPropertyKey` abstract operation to the evaluated property name:
   * If the value is a `Symbol`, it is used directly as the property key.
   * For all other types, the value is coerced into a string using the internal `ToString` operation.
5. **Reference Record Creation:** The operator evaluates to a Reference Record containing the base value and the resolved property key.

## Type Coercion Behavior

Because the operator enforces `ToPropertyKey` coercion, non-string primitives and objects exhibit specific behaviors when used inside the brackets:

```javascript theme={"dark"}
const target = {};

// 1. Number coercion
target[1] = "A"; 
// Engine coercively converts 1 to "1". Equivalent to target["1"]

// 2. Boolean coercion
target[true] = "B"; 
// Engine coercively converts true to "true". Equivalent to target["true"]

// 3. Object coercion
const keyObj = {};
target[keyObj] = "C"; 
// keyObj.toString() is called. Equivalent to target["[object Object]"]

// 4. Symbol preservation
const sym = Symbol("id");
target[sym] = "D"; 
// Symbols bypass string coercion and remain unique identifiers.
```

## Identifier Constraints and Private Fields

The `[]` operator bypasses the strict lexical grammar rules enforced by dot notation (`.`). Dot notation requires the property key to be a valid JavaScript `IdentifierName`, which fully supports Unicode characters (e.g., `obj.café`, `obj.π`), `$`, and `_`, but cannot start with a digit. Bracket notation, however, accepts any arbitrary string sequence.

```javascript theme={"dark"}
const obj = {};

// Valid in bracket notation, syntax error in dot notation
obj["invalid-identifier"] = true;
obj["123starts_with_number"] = true;
obj[""] = true; // Empty string is a valid property key
```

However, bracket notation cannot be used to access private class fields. Private fields (prefixed with `#`) are resolved lexically at compile time. Attempting to use bracket notation with a private field identifier string will attempt to access a standard public property, failing to reach the private field.

```javascript theme={"dark"}
class Example {
  #privateField = 10;

  test() {
    this.#privateField;    // Evaluates to 10 (Accesses private field)
    this["#privateField"]; // Evaluates to undefined (Accesses public property named "#privateField")
  }
}
```

## Array Indexing

In JavaScript, Arrays are standard objects, and array indices are standard object properties. The `[]` operator used on arrays is mechanically identical to its use on standard objects. The integer index is evaluated and coerced into a string key.

```javascript theme={"dark"}
const arr = ["X", "Y", "Z"];

arr[1]; 
// Evaluates to a Reference Record for base `arr` and property key "1".
// A subsequent [[Get]] operation on this Reference returns "Y".
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor JavaScript Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
