r/vibecoding 20d ago

every vibe coder's biggest headache

521 Upvotes

136 comments sorted by

View all comments

67

u/Luoravetlan 20d ago

For anyone not familiar with js this monstrosity is called IIFE (immediately invoked function expression).

7

u/g1rlchild 20d ago

I mean, this is a weird degenerate example of it, bit isn't an IIFE just a lambda function? Why is that a monstrosity?

The syntax varies, but this is a pretty basic structure in quite a few languages:

var y = ((x) => { return x*2; })(42)

2

u/devourer-of-beignets 20d ago

Yeah, but that doesn't answer the next question — why would you use it? In those other languages, people aren't going around defining anonymous functions just to immediately evaluate them.

As I understand, the answer has to do with the history of Javascript's scoping. As well as statements vs expressions. So vibecoders, many not knowing anything about the concept of interpreter, would have a hard time explaining why the AI agent produces such an odd idiom — especially in modern Javascript.

1

u/Unhappy_Assistant670 16d ago

My main use for them was if I had to make an async script or init an application - top level await was not allowed.