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

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -