
- 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 are Self-Invoking Anonymous Functions in JavaScript?
In JavaScript, the functions wrapped with parenthesis are called “Immediately Invoked Function Expressions" or "Self Executing Functions.
The purpose of wrapping is to the 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
- Self–invoking function in JavaScript?
- Invoking functions with call() and apply() in JavaScript
- Anonymous Wrapper Functions in JavaScript
- JavaScript closures vs. anonymous functions
- JavaScript Encapsulation using Anonymous Functions
- When to use anonymous JavaScript functions?
- What is the difference between anonymous and inline functions in JavaScript?
- What is a typical use case for JavaScript anonymous functions?
- What is the purpose of wrapping whole JavaScript files in anonymous functions?
- How to pass arguments to anonymous functions in JavaScript?
- PHP Anonymous functions
- The Anonymous Functions in Python
- What are functions in JavaScript?
- What are callback functions in JavaScript?
- What are generator functions in JavaScript?

Advertisements