JavaScript uses two logical non-operators (!!) Reasons for:
About the use of logical non-operators it's easy to say, if you don't know the logical operators section of JavaScript .
In some code it may be noted that some places use two logical non-operators, the first feeling is not necessary, such as the operand is true, the use of two logical non-return value or true, as if superfluous behavior, in fact, if it is not so.
Let's look at a code example:
grep:function(ELEMS,CALLBACK,INV) { var ret=[],retval; INV=!! INV; for (var i=0,length=elems.length;i<length;i++ ) { retVal=!! Callback (elems[/size][i][size=2],i); if (inv!==retVal) { Ret.push (elems[ } } return ret;}
The above code is a definition of the grep () function in the jquery source. The purpose of this is to be able to return false when the operand is null or undefined, rather than null or undefined, which makes it easier to do something. The above code, the third parameter can be omitted, when omitted can be used!! operator to convert undefined to false.
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=9118
For more information, refer to: http://www.softwhy.com/javascript/
JavaScript uses two logical non-operators (!!) The cause