C
It is not a single operator, it is the joint use of three operators (two ! and one ~).Before you enter into detail about what you do in the code, an explanation about each operator:! It's denial.Double denial (!!) mostly used to force the conversion of the type to booleansuch as:var token_null = null;
console.log( 'token_null =', token_null ); // null
console.log( '!token_null =', !token_null ); // true
console.log( '!!token_null =', !!token_null ); // false
console.log( '-----------' );
var token_undefined = undefined;
console.log( 'token_undefined =', token_undefined ); // undefined
console.log( '!token_undefined =', !token_undefined ); // true
console.log( '!!token_undefined =', !!token_undefined ); // false
console.log( '-----------' );
var token_0 = 0;
console.log( 'token_0 =', token_0 ); // 0
console.log( '!token_0 =', !token_0 ); // true
console.log( '!!token_0 =', !!token_0 ); // false
console.log( '-----------' );
var token_string = 'mi_token';
console.log( 'token_string =', token_string ); // "mi_token"
console.log( '!token_string =', !token_string ); // false
console.log( '!!token_string =', !!token_string ); // trueYou can see more information about double denial https://es.stackoverflow.com/a/125311 ~ is NOT to level bitA quick example:console.log(~0); // Es igual a -1
console.log(~-1); // Es igual a 0;
console.log(~11); // Es igual a -12;You can read more about the NOT at level bits https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Operadores/Bitwise_Operators#(Bitwise_NOT_o_Negaci%C3%B3n_a_nivel_de_bits) What are you doing there?Now that we finish the introduction, what you do !!~filters[key].indexOf(item[key]) is to return false only in the case that No. is found key within the array filters.Why?Because if the element is not found, .indexOf() returns -1, to which if we apply ~ becomes 0, which is equivalent to false.var noEncontrado = -1;
console.log(!!~noEncontrado);Now, if you pull out the !! is totally the same behavior because of how it works .every() As you can see here:// -1 simula la situación en la que indexOf() no encuentre el elemento, el resto de los valores haría referencia a la posición del elemento
var prueba1 = [1,0,2,3,-1].every(a=>!!~a); // da false
console.log(prueba1);
var prueba2 = [1,0,2,3,-1].every(a=>~a); // da false
console.log(prueba2);
var prueba3 = [1,0,2,3,1].every(a=>!!~a); // da true
console.log(prueba3);
var prueba4 = [1,0,2,3,1].every(a=>~a); // da true
console.log(prueba4);