Solved

Double Exclamation Marks

Posted on 2013-01-04
4
470 Views
Last Modified: 2013-01-04
I came across the line below is some code I was looking at.  Does anyone know what the double exclamation marks mean?

var w3cEventModel = !!document.addEventListener;


Thanks
Steve
0
Comment
Question by:steva
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
same as :
var notW3CEventModel = !document.addEventListener;
var w3cEventModel = !notW3CEventModel;

Open in new window


!null return return true
!!null return false

check this page : https://developer.mozilla.org/fr/docs/DOM/element.addEventListener
look for Internet Explorer section
0
 

Author Comment

by:steva
Comment Utility
But why?   How is

              (1)        var w3cEventModel = document.addEventListener;

different than

              (2)        var w3cEventModel = !!document.addEventListener;

In either case w3cEventModel will get an address if document.addEventListener exists and something that fails an if-clause (undefined or NULL or false) if it doesn't exist.

The code farther down is:

	// Use W3C method
	if (w3cEventModel) {
		addEvent(win, 'DOMContentLoaded', readyHandler);
	} else {
		// Use IE method
		addEvent(doc, "readystatechange", function() {
			if (doc.readyState === "complete") {
				removeEvent(doc, "readystatechange", arguments.callee);
				readyHandler();
			}
		});

Open in new window

Wouldn't  w3cEventModel = document.addEventListener  work here?

Thanks
Steve
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
1) object or null
2) boolean

More readable
0
 

Author Closing Comment

by:steva
Comment Utility
" More readable" - except for the !!  part.

Ok, I got it.

Thanks.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now