-4

How does this structure work when the function is anonymous?

 !function() { . . . }(); 
4
  • returned value NOT ed, !false Commented Jan 27, 2014 at 12:56
  • 3
    Also see stackoverflow.com/questions/9091289/…, which, in turn, seems to be a triple duplicate. ) Commented Jan 27, 2014 at 12:57
  • The anonymous function is executed, but the return value is not used anywhere. Commented Jan 27, 2014 at 13:03
  • There's no test for existence. The return value is negated and discarded. Commented Jan 27, 2014 at 13:37

2 Answers 2

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/

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

Comments

0

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

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.