Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

Double Exclamation Marks

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
steva
Asked:
steva
  • 2
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
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
 
stevaAuthor Commented:
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
 
leakim971PluritechnicianCommented:
1) object or null
2) boolean

More readable
0
 
stevaAuthor Commented:
" More readable" - except for the !!  part.

Ok, I got it.

Thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now