📦property access expression

use . / [] / ?. / ?.[] to evaluate object property / array element.

(operator)

use ., [], ?., ?.[], ?.() to evaluate the value of object property / array element.

// ⭐️ (normal) chaining
obj . identifier    // dot notation
obj   [ expr ]      // bracket notation (no "dot"❗️)

// ⭐️ optional chaining
obj  ?. prop        // dot notation
obj  ?. [ expr ]    // bracket notation
func ?. ( args )    // optional invocation

🈯 synonyms "property accessor", "property access expression", "chaining"

the "obj" part of the property accessor

  • the expression before . / [ (the obj part) is first evaluated.

  • if the value is null / undefined, TypeError is thrown.

  • use (?. / ?.[]) to guard againt this case.

the [expr] part of bracket notation []

  • is evaluated and converted to a string

property access and invocation expressions have higher precedence than any of the operators.

Last updated