-4

How does this structure work when the function is anonymous?

  !function() {             
            .
            .
            .

  }();
Tim
  • 8,256
  • 29
  • 96
  • 168

2 Answers2

2

With a return value.. you negate that with !

var x=!function(){return false}();
console.log(x);
// true

double negation

var pizza='pizza';
var x=!!function(){return pizza}();
console.log(x);
// true

// returns true if pizza is defined, not 'pizza'
// returns false if pizza is ''.

demo

http://jsfiddle.net/9shzF/1/

cocco
  • 15,256
  • 6
  • 53
  • 73
0

Pretty much as with any other thing. The anonymous function is autoexecuted, therefore returns a value, and the value is negated.

bgusach
  • 13,019
  • 10
  • 44
  • 61