0

I'm aware that a JavaScript function can be defined in this form

function name(parameter1, parameter2, parameter3) {
  // code to be executed
}

which consists of function keyword, followed by a name, followed by parentheses (), followed by curly brackets: {} in which the code to be executed is placed.

However, lots of real world js files look like this

(function(){...})();

where ... might be tens of thousands of lines, like this one which has 2 big blocks there.

Is that a form of JS framework? In the example of howler.js, the link above gives the source code of that framework which consists of 2 packages that are in the form of 2 block like (function(){...})();

Is my understanding correct?

singularli
  • 161
  • 6
  • 1
    That code creates a function and then calls it. This is called an "immediately invoked function expression" or "IIFE". In the examples you're talking about, it's being done to isolate any variables it creates, so they don't pollute other code. – Nicholas Tower Apr 29 '21 at 13:11
  • Check this: https://developer.mozilla.org/en-US/docs/Glossary/IIFE – Mayank Pandeyz Apr 29 '21 at 13:11
  • [What does this symbol mean in JavaScript?](https://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript) – Andreas Apr 29 '21 at 13:12

0 Answers0