When I use indexOf to check for a substring I often feel the statement is rather clumsy, especially if the variable name is particularly long.
== -1 part seems to get lost at the end of the expression and it takes me
an extra moment to parse the code. However, I found this brilliant little nugget
that makes it much easier to read.
Taking advantage of the fact that
~(-1) == 0 (and it is the only number with
this property), our statement becomes truthy or falsey and we can change
our previous example to