Prototype Library use of !! operator
Posted
by Rajat
on Stack Overflow
See other posts from Stack Overflow
or by Rajat
Published on 2010-06-18T02:19:44Z
Indexed on
2010/06/18
2:23 UTC
Read the original article
Hit count: 359
JavaScript
|javascript-library
Here is a snippet from Prototype Javascript Library :
Browser: (function(){
var ua = navigator.userAgent;
var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
return {
IE: !!window.attachEvent && !isOpera,
Opera: isOpera,
WebKit: ua.indexOf('AppleWebKit/') > -1,
Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1,
MobileSafari: /Apple.*Mobile/.test(ua)
}
})(),
This is all good and i understand the objective of creating a browser object. One thing that caught my eye and I haven't been able to figure out is the use of double not operator !! in the IE property.
If you read through the code you will find it at many other places. I dont understand whats the difference between !!window.attachEvent
and using just window.attachEvent
.
Is it just a convention or is there more to it that's not obvious?
© Stack Overflow or respective owner