0

What does this operator !!~ mean in typescript? Is it a combination of a bitwise operator and NOT operators?

eg return strict ? term === strValue : !!~strValue.indexOf(term);

mrJQuery
  • 191
  • 9
  • 3
    "*Is it a combination of a bitwise operator and NOT operators?*" yes. `~-1` is `0` so adding `!!` is a way of transforming the "not found" result of `.indexOf()` to `false`. – VLAZ Jul 16 '21 at 13:52
  • instead of using `!!~` which is hard to read, I suggest you to write: `strValue.indexOf(term) >= 0` – Yousaf Jul 16 '21 at 13:56
  • 1
    @Yousaf or `strValue.includes(term)` – VLAZ Jul 16 '21 at 13:57
  • @VLAZ yes, that is definitely better since the intention is to return a boolean value. – Yousaf Jul 16 '21 at 13:57
  • thanks guys, i did understand it now. @Yousaf i wasnt using it, i was reading source code and came across this weird operator. – mrJQuery Jul 16 '21 at 14:36

0 Answers0