javascript: What is a NOT NOT? (!! operator )

Val picture Val · Mar 23, 2011 · Viewed 8.9k times · Source

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);
}

Answer

sharpner picture sharpner · Mar 23, 2011

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