
- 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 a self-executing function in JavaScript?
The purpose of a self-executing is that those variables declared in the self-executing function are only available inside the self-executing function.
Variables declared in the self-executing function are, by default, only available to code within the self-executing function.
It is an immediately invoked function expression (IIFE). It is a function, which executes on creation.
Syntax
Here is 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?
- What is the purpose of a function prototype in C/C++?
- What is the purpose of MySQL TRIM() function?
- What is the purpose of new Boolean() in JavaScript?
- What is the purpose of the var keyword in JavaScript?
- What is the purpose of using MySQL CHAR_LENGTH() function? Which function is the synonym of it?
- What is the purpose of a register in a CPU and what are special purpose registers?
- What is the purpose of wrapping whole JavaScript files in anonymous functions?
- What is the purpose of a constructor in java?
- What is the purpose of COALESCE function? Explain with the help of an example.
- What is the purpose of a default constructor in Java?
- What is the purpose of ‘is’ operator in C#?
- What is the purpose of interfaces in java?
- What is the purpose of VOLUME in Dockerfile?
- What is the purpose of the `//` operator in python?

Advertisements