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
  • 572,313
  • 128
  • 898
  • 1,281

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
  • 118,038
  • 37
  • 189
  • 297