➕dot notation (.)
`obj . prop` syntax.
JS ⟩ statement ⟩ expression ⟩ operator ⟩ left-hand side ⟩ property access ⟩ dot natation
(property access expression) (🌟 chaining rules | table of operators )
use obj
. prop
to evaluate object property's value.
obj . prop // `prop` must be an "identifier".
🈯 synonyms: "chaining", "chaining operator", "dot notation"
replit:dot notation
// ⭐️ 1. prop: invalid identifier
// ------------------------------
undeclared.1 = 'bad'; // ⛔ SyntaxError: Unexpected number
// ^^
// ⭐️ 2. obj: "undeclared"
// -------------------------------
undeclared.prop; // ⛔ ReferenceError: 'undeclared' is not defined
// ⭐️ 3. obj: "nullish"
// -------------------------------
null.prop // ⛔ TypeError: Cannot read properties of null
// ⭐️ 4. obj: not "nullish"
// -------------------------------
(18).prop; // ❗ undefined (no such `prop`)
(18).toString(16); // ❓ "12" (property value, could be any value)
// object
let obj = {};
// ┌───────────────────┐
// │ valid identifiers │
// └───────────────────┘
obj.$1 = 'joe'; // ✅ can begin with $, _
obj.var = 'OK'; // ✅ reserved word is allowed❗
Last updated
Was this helpful?