1

Is there a way to synthetize a "nil or empty" testing like this one ?

if (!shoppingCartLine ||
    !shoppingCartLine.relationships ||
    !shoppingCartLine.relationships.offer ||
    !shoppingCartLine.relationships.offer.links ||
    !shoppingCartLine.relationships.offer.links.self)
return null;

to an helper like this :

if (isNilOrEmpty(shoppingCartLine.relationships.offer.links.self))
return null;

or maybe like C#6.0 Null-Conditional Operator :

if (!shoppingCartLine?.relationships?.offer?.links?.self)
return null;

without throwing an error :

Cannot read property 'links' of undefined
Deividas
  • 6,437
  • 2
  • 26
  • 27
Guillaume R
  • 105
  • 1
  • 1
  • 7

0 Answers0