المعرفة:: JavaScript الحالة::مؤرشفة المراجع:: The Complete JavaScript Course 2022 From Zero to Expert
IIFE
- Sometimes in JavaScript, we need a function that disappears right after it’s called once).
- This can be done by writing the function expression without assigning it to any variable then wrapping all of this into parentheses (transforming the statement into an expression).
- It’s useful for encapsulating data, since inner scope won’t be accessed by any outer one.
- This technique will be needed with
async
/await
.
- In modern JavaScript IIFE is not used widely because blocks can be used for achieving the same behavior with variables.