!function () {}();
views:
91answers:
3
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
2010-09-20 21:25:09
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
2010-09-20 21:27:13
question is clear, your answer doesn't contain *answer*, just well known facts
Andrey
2010-09-20 21:35:53
+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
2010-09-20 21:28:16