What does = +_ mean in JavaScript

In case you were wondering why it is used in that situation, it is a shorthand for finding out if indexOf method found something.

indexOf returns -1 when it doesn't find something, and >= 0 when it does. So when you do ~-1 you get 0 (a falsy value) and when you do it on anything else you get a truthy value.

So:

if( ~str.indexOf( "something" ) ) {
...
}

Is a shorter way of saying

if( str.indexOf( "something" ) !== -1 ) {
...
}

If you are wondering how is -1 the NOT of 0, then read here


It's the Bitwise NOT operator:

https://developer.mozilla.org/en/JavaScript/Reference/Operators/Bitwise_Operators