Can someone explain this 'double negative' trick?

Posted by ProfessionalAmateur on Stack Overflow See other posts from Stack Overflow or by ProfessionalAmateur
Published on 2011-01-13T23:39:06Z Indexed on 2011/01/13 23:53 UTC
Read the original article Hit count: 252

Filed under:
|

Hello, I am by no means an expert at javascript, but I have been reading Dave Pilgrim's "Dive into HTML5" webpage and he mentioned something that I would like a better understanding of.

He states:

"Finally, you use the double-negative trick to force the result to a Boolean value (true or false)."

function supports_canvas() {
  return !!document.createElement('canvas').getContext;
}

If anyone can explain this a little better I would appreciate it!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html5