2

In jQuery javascript code I see

(function(window, undefined) {
})(window);

And in Twitter

!function(window, undefined) {
}(window);

Can someone tell what the difference between these two approaches is?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375

1 Answers1

1

Using the ! operator before the function causes it to be treated as an expression, so we can call it:

!function() {}()

http://jasonlau.biz/home/faq/what-is-the-exclamation-mark-used-for-in-code

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307