0

So I was looking at the minified javascript that webpack created from some ts files using awesome-typescript-loader and noticed that the first thing is does is

!function(e){...}

What does the ! before a function do?

I'm familiar with the (function(){})() syntax. Is it similar to that?

Drew Landgrave
  • 1,195
  • 2
  • 11
  • 22
  • it is forcing the following expression/IIFE to execute. the better syntax would be the [`void` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void). – Nina Scholz Dec 19 '18 at 15:41
  • 1
    [What does the exclamation mark do before the function?](https://stackoverflow.com/questions/3755606/what-does-the-exclamation-mark-do-before-the-function) and [JavaScript plus sign in front of function name](https://stackoverflow.com/questions/13341698/javascript-plus-sign-in-front-of-function-name) – t.niese Dec 19 '18 at 15:43
  • 2
    The snippet actually doesn't do anything. Are you sure there are not the pair of parentheses at the end of the expression? – Teemu Dec 19 '18 at 15:44
  • 1
    Looks like they took minifying very seriously: `!` is one character less than `(` and `)` around the function, and still forces execution. – Peter B Dec 19 '18 at 15:48
  • `!function(e){console.log('xxx')}` won't be executed, are u sure about the execution thing? – felixmosh Dec 19 '18 at 20:08

0 Answers0