0

I have an issue with ternary operator expression.

AssociatedItemType.ExRatedTag ? session?.data.reloadRow(ids) : this.reloadItemRows(this.prepareItemsIdentities(ids)!),

AssociatedItemType is enum.

I found out that const ? 1 : 2 always returns 1. Why is that so? And what should I do to make my expression work as expected. I mean if true run

session?.data.reloadRow(ids)

if not

this.reloadItemRows(this.prepareItemsIdentities(ids)!)

GGotchaA
  • 165
  • 1
  • 1
  • 10

1 Answers1

0

Can you try in your code Boolean(AssociatedItemType.ExRatedTag) if it always returns true, then the problem is in AssociatedItemType.ExRatedTag.

AssociatedItemType.ExRatedTag might return an empty object or an empty array, or the string "false" and all of that are evaluated to true in javascript

Check https://developer.mozilla.org/en-US/docs/Glossary/Truthy and https://developer.mozilla.org/en-US/docs/Glossary/Falsy for more about what javascript considers true or false.

Constantin Chirila
  • 1,979
  • 2
  • 19
  • 33