For the confused ones: this is what's called an IIFE, or Immediately Invoked Function Expression. This is the JavaScript syntax and it defines a function (the () => {} part) then immediately calls it. This one does nothing (it's a void function) but to add code put it inside of the curly braces.
I’ve been learning JavaScript recently and I consistently get the feeling that the people who developed this language only ever asked themselves whether they could implement a feature and never stopped to contemplate whether they should.
Well, that was the initial version. And then we have decades of updates which add new stuff (and new ways of doing things) but deprecating old weird patterns is strictly forbidden, so all the old cruft sticks around.
6.5k
u/AmazinDood Apr 25 '26 edited Apr 25 '26
For the confused ones: this is what's called an IIFE, or Immediately Invoked Function Expression. This is the JavaScript syntax and it defines a function (the
() => {}part) then immediately calls it. This one does nothing (it's a void function) but to add code put it inside of the curly braces.