jane.boyfriend?.money.more

chaining example.

JSvalueobjectaccessing propertieschaining rules ⟩ example (jane)

👉 see chaining rules for more info.

// jane
let jane = { 
    home: null,
    boyfriend: { name: 'Joe' }
};

//  ⭐ chaining methods       N     NN    // N: nullish,   NN: non-nullish
// ------------------------------------
//           chaining  ( .)  ⛔     ✅    // ⛔: TypeError (cannot read property)
//  optional chaining  (?.)  🈚     ✅    // 🈚: undefined (⭐ short-circuiting)
//      leaf property  (P )  ✅     ✅    // ✅: OK (no error)
// ------------------------------------

jane. boyfriend?. money. more,   // jane     : (NN. ) -> ✅
//    ╰──NN ?.──╯                // boyfriend: (NN?.) -> ✅
//                ╰─N.─╯         // money    : (N.  ) -> ⛔
                             
jane. boyfriend?. money?. more, 
//                ╰─N?.─╯        // money    : (N?. ) -> 🈚 (⭐ short-circuiting)
                                 // more     : ignored

Last updated