

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- What is the purpose of MySQL TRIM() function?
- What is the purpose of a function prototype in C/C++?
- 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?
- Self–invoking function in JavaScript?
- What is the purpose of a constructor in java?
- What is the purpose of a register in a CPU and what are special purpose registers?
- What is the purpose of System Programs?
- What is the purpose of System Calls?
- What is the purpose of any research?
- What is the purpose of Human Life?
- What is the purpose of Risk Management?
- What is the purpose of COALESCE function? Explain with the help of an example.
- What is the purpose of a default constructor in Java?
Advertisements