Possible Duplicate:
What is the !! (not not) operator in JavaScript?
Jquery Library souce code of $.grep.....
grep: function( elems, callback, inv ) {
var retVal,
ret = [],
i = 0,
length = elems.length;
inv = !!inv;
// Go through the array, only saving the items
// that pass the validator function
for ( ; i < length; i++ ) {
retVal = !!callback( elems[ i ], i );
if ( inv !== retVal ) {
ret.push( elems[ i ] );
}
}
return ret;
},
In this example above is jquery grep on souce code of jquery library. Why he make inv as default is undefined and he changed to boolean and same thing retVal store the !!callback and change to the boolean. The issue is how if statement Works...?? Can give me some more details explanation..!! Thanks.
retVal = !!callback( elems[ i ], i );
if ( inv !== retVal ) {
ret.push( elems[ i ] );
}