Tilde is the bitwise not operator. The .indexOf()
method returns the index of the found match in a string (or in an array) or -1
if the substring was not found.
Because 0 == false
tilde may be used to transform -1
in 0
and viceversa:
> ~1
-2
> ~0
-1
> ~-1
0
~file.indexOf('.js')
is equivalent to file.indexOf('.js') === -1
or file.indexOf('.js') < 0
. The last two examples are more clear to understand that the first one.