0

I'm looking at some JavaScript code and I can't figure out why a logical operator (!) is being used in function declaration. This is a tiny extract:

   ! function (a) {

        ! function (a)
        {
            "use strict";
            a.Shorthand = {
                UI: {},
                helpers: {},
                Data: {}
            }
        }(window),  ...
}(!1);

I'm pretty sure its an IIFE (when complete) and it's main purpose is minification but that's as far as I go. I've not come across any explanation. When the rest of the code is there it all works. thanks

user3836754
  • 273
  • 1
  • 3
  • 6

1 Answers1

0

It's about function expression needed instead of function declaration for IIFE. If function is used as expression it can be invoked imidiatelly. If it's not a part of an expression it can't so this code won't work:

function(){}()

while this will work:

!function(){}()
(function(){}())
(function(){})()
var a = function(){}()
Nick Messing
  • 494
  • 5
  • 14