0

Here is an example to become more specific. All of the answers is same. If i face some challenge which way should i follow ? Actually how they work with their own logic. Want to be clear.

var obj = {
    a: "First",
    b: {
        x: 1,
        y: 2
    },
   c: "last"
}

console.log(obj?.b?.x); // 1 
console.log(obj.b.x ?? obj.b); // 1 
console.log(obj && obj.b && obj.b.x); // 1 
console.log(obj.b ? obj.b.x : undefined); // 1 
Yadab Sd
  • 433
  • 2
  • 7
  • ?. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining – Ifaruki Aug 03 '20 at 13:43
  • ?? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator – Ifaruki Aug 03 '20 at 13:44
  • condition ? [true] : [false] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator – Ifaruki Aug 03 '20 at 13:45
  • && https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND – Ifaruki Aug 03 '20 at 13:46

0 Answers0