PinoyTech.org

CodeIgniter, Kohana, Mootools, jQuery and CSS

Javascript double exclamation point !!

Posted by teejay on March 8, 2010

I spend my time developing applications and have geared most of my time to learn and hopefully 'master' javascript. One of the things I've noticed while reading the Mootools Core source code(Yeah, I'm hard core :p ) is the double exclamation points.

function $chk(obj){
 return !!(obj || obj === 0);
};

What does that mean?

It turns out that the double exclamation points are just inverting boolean values just like the normal exclamation points. But double exclamations means inverting it twice.

Let's take the snippet from the Mootools Core source code.

function $chk(obj){
 return !!(obj || obj === 0);
};

The function literally means that if the object has a value of 0(zero) or and is existing object, it returns true.

The exclamation outside the parenthesis inverts that boolean value to FALSE. The next exclamation will then invert it to TRUE.

If this seems too easy for you, good for you. I'm still learning. Thanks for your time.

Categories: Clientside

Tags: javascript, mootools

1 Comments

jhon

It’s a really good and informative post about java script and it it also carpenters in swindon

April 21st 2010

Comments are not allowed