It's really good question! Every people didn't care about why it's use?
As the name implies, IIFEs are functions that are executed immediately after they are defined — there’s no need to call them explicitly.
Generally, this is how you define and execute (at a later point) a function:
function myFunction() {
// ...
}
myFunction();
But if you want to execute the function immediately after it is defined, you have to wrap the whole declaration in parentheses (to convert it to an expression) and execute it by adding two more parentheses (passing any arguments the function may take).
Either this way:
( function myFunction(/* arguments */) {
// ...
}(/* arguments */) );
In TypeScript, you use curly braces to wrap an IIFE, put all the logic you want inside it (if/else, switch, ternary operators, etc.), and return whatever you want to render. For example, here’s how the logic to render the save/edit button could look with an IIFE:
( (/* arguments */) => {
// ...
} ) (/* arguments */);
I hope my answer help you understand =>
operator.