
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What is the purpose of wrapping whole JavaScript files in anonymous functions?
The purpose of wrapping is to a namespace and control the visibility of member functions. It wraps the code inside a function scope and decreases clashing with other libraries. This is what we call Immediately Invoked Function Expression (IIFE) or Self Executing Anonymous Function.
Syntax
Here’s the syntax −
(function() { // code })();
As you can see above, the following pair of parentheses converts the code inside the parentheses into an expression −
function(){...}
In addition, the next pair, i.e. the second pair of parentheses continues the operation. It calls the function, which resulted from the expression above.
- Related Articles
- What is the difference between anonymous and inline functions in JavaScript?
- Anonymous Wrapper Functions in JavaScript
- What are Self-Invoking Anonymous Functions in JavaScript?
- What is a typical use case for JavaScript anonymous functions?
- JavaScript closures vs. anonymous functions
- JavaScript Encapsulation using Anonymous Functions
- When to use anonymous JavaScript functions?
- The Anonymous Functions in Python
- How to pass arguments to anonymous functions in JavaScript?
- PHP Anonymous functions
- What is an anonymous function in JavaScript?
- What is the purpose of new Boolean() in JavaScript?
- What is the purpose of the var keyword in JavaScript?
- Does use of anonymous functions affect performance?
- What is the purpose of a self-executing function in JavaScript?

Advertisements