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
  • 19,786
  • 13
  • 77
  • 119

1 Answers1

0

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
  • 34,922
  • 8
  • 55
  • 102