0

I´m trying to make my comparation more concise this way, but it doesnt work:

if (this.filterControl.value === ("YES" || "NO"))

This one works:

if (this.filterControl.value === "YES" || this.filterControl.value === "NO")
Jmainol
  • 357
  • 4
  • 18
  • `"YES" || "NO"` is always `"YES"`, because `"YES"` is a [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) value. What you could try with multiple values is [`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes). Like `['YES', 'NO'].includes(this.filterControl.value)`. – Lain Feb 14 '23 at 15:31
  • *"but it doesnt work"* - It "works" in the sense that it successfully performs the logic it's designed to perform. That logic just isn't what you thought it would be. *"This one works"* - It sounds like you've solved the problem then. However, if what you're **implying** (but not asking) is how to test a value against a list of values, the linked duplicate can help with that. – David Feb 14 '23 at 15:33
  • 1
    Weird idea, you're not trying to make a comparison more concise, you're trying to make it more ambiguous... ;) – Mister Jojo Feb 14 '23 at 15:35

0 Answers0