Solved

Double Exclamation Marks

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP: Filling Out/Creating a PDF 29 163
Why does my submit button remain disabled 3 33
Difference between Leaflet and MapBox? 5 45
Why is my select returning NaN 21 35
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

737 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