2012-07-11

JavaScript: Exclamation Before function

I come across JavaScript code like this today:

!function(d,s,id){…}(…);

What does that !function mean?

Turns out, it is equivalent to this:

(function(d,s,id){…})(…);

The exclamation makes the function a expression. (it's the boolean “not” operator.) People do this hack to save one character worth of source code file size. Silly.