- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Self–invoking function in JavaScript?
The self-invoking function in JavaScript are known as Immediately Invoked Function Expressions (IIFE). Immediately Invoked Function Expressions (IIFE) is a JavaScript function that executes immediately after it has been defined so there is no need to manually invoke IIFE.
Following is the code for self-invoking function (IIFE) in JavaScript −
Example
<!DOCTYPE html> <html lang="javascript:void(0);en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; } </style> </head> <body> <h1>JavaScript Immediately Invoked Function Expressions (IIFE)</h1> <div class="sample"></div> <script> let sampleEle = document.querySelector(".sample"); (function () { sampleEle.innerHTML = "This code is invoked immediately as soon as it is defined"; })(); </script> </body> </html>
Output
The above code will produce the following output −
- Related Articles
- Self–invoking function in JavaScript?
- What are Self-Invoking Anonymous Functions in JavaScript?
- Invoking functions with call() and apply() in JavaScript
- What is the purpose of a self-executing function in JavaScript?
- Invoking MySQL Programs
- Smart / self-overwriting / lazy getters in javaScript?
- Check for a self-dividing number in JavaScript
- Self Crossing in C++
- self in Python class
- Self Destructing Code in C
- The Cognitive Self
- The Social Self
- Function returning another function in JavaScript
- Create self-contained content in HTML5
- Concept of Self in Different Tradition
- CSS align-self property

Advertisements