re: What is an IIFE? VIEW POST

FULL DISCUSSION
 

There are useful use for IIFE in modern apps. For instance when you need an expression and don't want to define a separate function (e.g for clarity, or to have access to variables through the closure instead of passing them as arguments).
In react for example, if you need some piece of logic within jsx tags and can't only rely on ternary/boolean logic, an IIFE can be handy.
In that regard, IIFE are an alternative to do-expressions (github.com/tc39/proposal-do-expres...).

 

Thanks, I have not done much in the world of React, outside of my own curiosity. I have seen and used IIFE's pretty regularly in some older angularJs apps. Used mostly for the ability to work on some logic without affecting the global window of properties. I'll have to take a look at React's do-expression.

 

React is just one example where IIFE can be useful though the use case I was referring to applies anywhere where you need/want an expression and need to perform some logic.
do-expressions is a new js feature but isn't limited to react either.

Gotcha, re-read what you stated, makes sense when thinking about something like a ternary operation not quite fitting the bill.

code of conduct - report abuse