🔧 What is an IIFE (Immediately Invoked Function Expression) and Why Should You Care?
Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to
An (IIFE) Immediately Invoked Function Expression is a function that executed as soon as it’s defined.
It’s a common design pattern that helps create a private scope and avoiding polluting the global scope.
(function () {
// Code inside IIFE
})();
The function declare inside parentheses and trailing () immediately invoke it.
This can be useful when you need to fetch data immediately after the page loads, here the example:
(async function () {
try {
let response = await fetch("https://jsonplaceholder.typicode.com/posts");
let data = await response.json();
console.log(data);
} catch (error) {
console.error("Error fetching data:", error);
}
})();
🔧 IIFE(immediately-Invoked function Expression)
📈 93.92 Punkte
🔧 Programmierung
🔧 Immediately Invoked Function Expression (IIFE)
📈 93.92 Punkte
🔧 Programmierung
🔧 Function declaration and Function Expression
📈 32.24 Punkte
🔧 Programmierung
🔧 Function Declaration vs Function Expression
📈 30.93 Punkte
🔧 Programmierung
🔧 JavaScript: O que são funções IIFE?
📈 28.58 Punkte
🔧 Programmierung