!function () {}();
The function:
function () {}
returns nothing (or undefined).
Sometimes we want to call a function right as we create it. You might be tempted to try this:
function () {}()
but it results in a SyntaxError
.
Using the !
operator before the function causes it to be treated as an expression, so we can call it:
!function () {}()
This will also return the boolean opposite of the return value of the function, in this case true
, because !undefined
is true
. If you want the actual return value to be the result of the call, then try doing it this way:
(function () {})()