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
Solved

Double Exclamation Marks

Posted on 2013-01-04
4
473 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
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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

828 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