?
Solved

Double Exclamation Marks

Posted on 2013-01-04
4
Medium Priority
?
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 38744952
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
ID: 38745433
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 2000 total points
ID: 38745438
1) object or null
2) boolean

More readable
0
 

Author Closing Comment

by:steva
ID: 38745501
" More readable" - except for the !!  part.

Ok, I got it.

Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…

770 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