11

Possible Duplicate:
What is the !! operator in JavaScript?

What is a not not in javascript I have seen this a few times :)

function foo(){
    return !!(window.history);
}
4
  • 2
    Exact duplicate: stackoverflow.com/questions/784929/… Commented Mar 23, 2011 at 11:44
  • 1
    It's a duplicate, but that duplicate question barely mentions why it's used. In your case, it's the bottom answer: it's an idiom to check 'is defined'. Commented Mar 23, 2011 at 11:48
  • @rup I agree the answers there pretty wack, I didnt understand half of them answers and their technical B-S, they should be more friendly with their answer and not assume everyone is on their level :) especially when someone asks :) Commented Mar 23, 2011 at 12:05
  • The title of this question is much easier to find then the duplicate one Commented Sep 10, 2011 at 11:17

2 Answers 2

12

i believe it is used for enforcing boolean types...

for example

if("true" == true){
    alert("1");
}else{
    if(!!"true" == true){
        alert("2");
    }
}

alerts 2 not 1

Sign up to request clarification or add additional context in comments.

2 Comments

This is horri-bad. Try if(!!"false" == true) { alert("false"); } and see what happens.
I did not say you should use it
5

I think it used to [not so] implicitly cast value to boolean type

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.