This commit is contained in:
Ilya Kantor 2019-07-01 18:14:00 +03:00
parent ce4119672d
commit 9a7deaeab9

View file

@ -322,7 +322,7 @@ alert( ~-1 ); // 0, the same as -(-1+1)
*/!*
```
As we can see, for 32-bit integers `~n` is zero only if `n == -1`.
As we can see, `~n` is zero only if `n == -1` (that's for any 32-bit signed integer `n`).
So, the test `if ( ~str.indexOf("...") )` is truthy only if the result of `indexOf` is not `-1`. In other words, when there is a match.