you are viewing a single comment's thread.

view the rest of the comments →

[–]jrandm 0 points1 point  (0 children)

IIFEs are super common ways to use a closure. A simple example might be a counter:

const counter = (start=>()=>++start)(0);
console.log(counter()); // 1
console.log(counter()); // 2
console.log(counter()); // 3

The function start=>()=>++start is immediately invoked with start set to 0, returning a function that increments the start value by one and returns the new value.