TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
[] (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
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:
- Base Evaluation: The
objectexpression to the left of the brackets is evaluated to retrieve the base value. - Expression Evaluation: The
expressioninside the brackets is evaluated to retrieve the property name value. - Coercibility Check (
RequireObjectCoercible): The engine checks if the base value is object-coercible. If the base evaluates tonullorundefined, aTypeErroris 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 customtoString()method on an object) will not execute. - Key Coercion (
ToPropertyKey): The engine applies the internalToPropertyKeyabstract 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
ToStringoperation.
- If the value is a
- 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 enforcesToPropertyKey coercion, non-string primitives and objects exhibit specific behaviors when used inside the brackets:
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.
#) 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.
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.
Master JavaScript with Deep Grasping Methodology!Learn More





