views:

237

answers:

3
+2  Q: 

why use the "!!!"?

as follow codes:

var a = {};
if(!!!a[tabType]){
   a[tabType] = [];
   a[tabType].push([self,boxObj]);
}else{
   a[tabType].push([self,boxObj]);
}

i think !!!a[tabType] equals !a[tabType] why use the "!!!" not "!" ?

thank you!

+8  A: 

The !! construct forces conversion to a boolean. I don't see the point of it here.

x1a4
Perhaps the coder was angry? It *is* JavaScript... ;-P
Thanatos
amazing how many people are voting up answers that are downright false. voted them down, and you up. just goes to show how everyone thinks they know javascript, but very few actually do.
Matt Briggs
@Thanatos http://wtfjs.com/
alex
@Matt Briggs I'm sure you know, but `!!` works in other languages too, so I would of thought more people would know about it.
alex
@Matt Briggs: x1a4 might be a little off, but the intent is correct: `!` forces coercion to a boolean value, so `!` is useful, even `!!` is useful, but what's the point of `!!!`? None that we can see.
Thanatos
@thanatos: granted, but at least the statement he made is true. chances are someone used !!, then someone else wanted to not it, didn't know what !! did so just added another bang. at the time I posted this, jacobs answer had 7 upvotes and this one had none, which is why I made my comment
Matt Briggs
A: 

It makes it more obvious to the reader. I would just put spaces around it like this:

if( ! a[tabType]){

But it looks like this programmer is pretty much opposed to spaces.

yjerem
umm... no ` ` ` `
Earlz
@Earlz: Well what else could it possibly be for? Other answers have already explained that it serves no computational purpose... may the coder was just trying to style it up a bit - or perhaps make it obvious as jeremy suggested.
Cam
@inc I would guess they were doing it to amuse themselves before I would guess they were trying to "make it obvious"; `!!!` is just going to confuse people that see it, not make them think `oh, obviously that's a not symbol`. It's the same as doing `*******printf`; it looks amusing but will mostly just confuse people that see it
Michael Mrozek
I would guess that they didn't know what they were doing @incred @Mich. That's about as good as putting `if(x==true==true)`. Someone only does that if they are blindly trying to get a piece of (usually copied and pasted) code to work for them.
Earlz
oh, I wasn't serious...
yjerem
+2  A: 

There is no point at all. It is precisely equivalent to using !.

Tim Down