- 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
Anonymous Wrapper Functions in JavaScript
Anonymous functions are used to wrap code snippets, JavaScript libraries, functions etc to control their visibility and the namespace so that there shouldn’t be any conflict with other libraries code. IIFE (Immediately Invoked Function Expressions) are used for this purpose.
Following is the code to implement Anonymous Wrapper Functions in JavaScript −
Example
<!DOCTYPE html> <html lang="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; } .result { font-size: 20px; font-weight: 500; color: blueviolet; } </style> </head> <body> <h1>Anonymous wrapper functions in JavaScript</h1> <div class="result">0</div> <br /> <script> let resEle = document.querySelector(".result"); (function () { resEle.innerHTML = "This piece of code is automatically executed as it is inside an IIFE"; })(); </script> </body> </html>
Output
- Related Articles
- JavaScript Encapsulation using Anonymous Functions
- JavaScript closures vs. anonymous functions
- When to use anonymous JavaScript functions?
- What are Self-Invoking Anonymous Functions in JavaScript?
- How to pass arguments to anonymous functions in JavaScript?
- PHP Anonymous functions
- The Anonymous Functions in Python
- 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?
- Does use of anonymous functions affect performance?
- What is an anonymous function in JavaScript?
- Regular functions vs Arrow functions in JavaScript?
- Wrapper Clothing
- Arrow functions in Javascript

Advertisements