views:

91

answers:

3
!function () {}();
A: 

It returns whether the statement can evaluate to false. eg:

!false      // true
!true       // false
!isValid()  // is not valid

You can use it twice to coerce a value to boolean:

!!1    // true
!!0    // false

So, to more directly answer your question:

var myVar = !(function(){ return false; })();  // myVar contains true
gilly3
A: 

An exclamation mark in Javascript is the "not" operator. It the function returns false (or null or zero), then !f will be true. Alternatively if the result is true (or any non-null, non-zero value) then !f will be false.

Nick Fortescue
question is clear, your answer doesn't contain *answer*, just well known facts
Andrey
+5  A: 

The function:

function () {}

returns nothing (or undefined).

So, this expression calls that function:

function () {}()

and using the ! operator on the result converts the undefined result to true:

!function () {}()

As this will show you:

alert( !function () {}());
Michael Burr
who can ever need this?
Andrey
this is the **only** answer that explains case in the question, bravo!
Andrey
i think the pouint is that if the function return nothing it will be true, thanks
Sep O Sep