1

I'm using a nice bundle that integrates Bootstrap with Symfony. It contains some javascript for dealing with form field collections. When I was looking at the code to see how they did it I ran across this:

!function($){

  //function body

}(window.jQuery);

I'm familiar enough with javascript to recognize (function(arg){})(anArg); as a self-executing function, but since this lacks the enclosing parentheses I'm at a loss as to what ! is negating.

What is happening here?

Community
  • 1
  • 1
dnagirl
  • 20,196
  • 13
  • 80
  • 123

1 Answers1

1

The preceding ! takes the un-parseable statement, and allows it to to be parsed by the JS engine, which in turn returns true.

function(){}();
SyntaxError: Unexpected token (

!function(){}();
>>true

Source

Community
  • 1
  • 1
void
  • 36,090
  • 8
  • 62
  • 107