0
const result = something[dynamicValue]

Given the above code, I can get error of Cannot read property 'x' of null because something is undefined, how do I fallback check to void error? should I do something like this

const result = something && something[dynamicValue]
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
alice_morgan
  • 151
  • 7
  • `const result = something?.[dynamicValue]` – Andreas Apr 15 '21 at 08:53
  • [Is there a null-coalescing (Elvis) operator or safe navigation operator in javascript?](https://stackoverflow.com/questions/6613952/is-there-a-null-coalescing-elvis-operator-or-safe-navigation-operator-in-javas) – Andreas Apr 15 '21 at 08:54

0 Answers0