0

I found a script in Vue project. But I don't know what this || {}).data and || {}).message does?

const message = ((err.response || {}).data || {}).message || 'Something went wrong'
pmt9
  • 51
  • 1
  • 6
  • 1
    It's a way of accessing the `message` key without throwing an error when the intermediate properties don't exist https://stackoverflow.com/a/4034468 – CertainPerformance Feb 04 '20 at 09:26
  • 1
    Also relevant: 1. [What does β€œvar FOO = FOO || {}” (assign a variable or an empty object to that variable) mean in Javascript?](https://stackoverflow.com/questions/6439579/what-does-var-foo-foo-assign-a-variable-or-an-empty-object-to-that-va) 2. [JavaScript OR (||) variable assignment explanation](https://stackoverflow.com/questions/2100758/javascript-or-variable-assignment-explanation) 3. [What does the construct x = x || y mean?](https://stackoverflow.com/questions/2802055/what-does-the-construct-x-x-y-mean) – VLAZ Feb 04 '20 at 09:27

0 Answers0