javascript - How to use the !! expression? -
possible duplicate:
what !! (not not) operator in javascript?
reference - symbol mean in javascript?
i find js code write : !!undefined , !!false;
the jquery source code (jquery 1.7.0.js: line 748):
grep: function( elems, callback, inv ) { var ret = [], retval; inv = !!inv; // go through array, saving items // pass validator function ( var = 0, length = elems.length; < length; i++ ){ retval = !!callback( elems[ ], ); if ( inv !== retval ) { ret.push( elems[ ] ); } } return ret; }
!
means opposite
so !!
means double opposite
.
it commonly used in case:
var check = !!(window.something && window.runthis) //if exists , runthis exists, //check = true //if 1 of them not exist, //check = false
commonly used in checking browser compatibly.
Comments
Post a Comment