Skip to content

kenanturgay/Self-Invoked-Function-Structure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 

Repository files navigation

Self-Invoked Function (IIFE) in JavaScript – Simple Example

This project shows how to use a self-invoked function (also called IIFE) in JavaScript.
It is a simple and clean example for beginners to understand how this structure works.

πŸ“Œ What is a Self-Invoked Function?

A self-invoked function is a function that runs immediately after it is created.
You don’t need to call it manually. It runs by itself.

(() => {
  // Your code here
})();

🧠 Why use it?

  • Keeps your code private and safe
  • Stops global variable pollution
  • Helps organize JavaScript code better
  • Good for creating modules

πŸ“‚ What's in the project?

The JavaScript file includes:

Function What it does
self.init() Runs when the page is ready
self.reset() Clears or resets the UI
self.buildCSS() Adds CSS styles
self.buildHTML() Adds HTML elements to the page
self.setEvents() Adds click or input events
self.fetchData() Gets data from an API (using async/await)
self.saveToStorage() Saves data to localStorage in the browser

πŸ“„ Code Commented Line by Line

All code lines include easy comments so you can learn how it works step by step.

πŸš€ How to Use

  1. Open the HTML file in your browser
  2. Open the developer console (F12 or right click β†’ Inspect β†’ Console)
  3. Watch how the function runs automatically

πŸ” Keywords (for SEO)

JavaScript self-invoked function, JavaScript IIFE example, beginner JavaScript structure,
how to organize JavaScript code, self-invoking function explained, JavaScript module pattern,
$(document).ready with IIFE

πŸ’‘ Use Cases

  • Building widgets or UI components
  • Creating isolated modules
  • Writing plugin-like behavior without polluting the global scope

πŸ‘¨β€πŸ’» Author

This example was created for beginners who want to understand IIFE in JavaScript.
You are free to use, fork, or improve it.


⭐ If you find this useful, feel free to star the repo!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published