0

Possible Duplicate:
What does the exclamation mark do before the function?

I;ve just came across a tablesorter plugin, and while looking at the source, I found that plugin is set up with Self-Invoking Anonymous Function - nothing unusual. Yet, I don't know what is the purpose of leading ! character:

!(function($) {})(jQuery);

I mean, how does it differ from this:

(function($) {})(jQuery);
Community
  • 1
  • 1
dragonfly
  • 17,407
  • 30
  • 110
  • 219
  • 1
    Duplicates: http://stackoverflow.com/questions/8305915/function-vs-function http://stackoverflow.com/questions/9475110/not-self-invoking-anonymous-functions?rq=1 – Kos Jan 15 '13 at 09:22
  • @sachleen - Interesting related question. But it seems the plug-in author misunderstood the technique... – Álvaro González Jan 15 '13 at 09:23

1 Answers1

2

For all intents and purposes, it doesn't differ at all. It negates the return from the function call, but since the return value isn't assigned to anything then it's pointless.

Andy E
  • 338,112
  • 86
  • 474
  • 445
  • It makes a difference when this code is concatenated with another via a minifier – Kos Jan 15 '13 at 09:22
  • 1
    @Kos: yes, but a minifier would not put the function in braces. The examples the OP gave are different from the scenario where the `!` would be used to save one measly byte. – Andy E Jan 15 '13 at 09:23