Hacker News new | past | comments | ask | show | jobs | submit login

Avoid globals at all costs - use IIFE [1] instead, wrapping your function in parenthesis and invoking it right away.

[1] https://developer.mozilla.org/en-US/docs/Glossary/IIFE




If you have access to `let`, you can just put `let` declarations into a block. No need for a function to establish scope.


When, today, does it make more sense to organize things around IIFEs and not ES6 modules?


It's 2022, you can use ES2015 modules now. We can leave IIFE to the dustbin of the past.


And then get coworkers to remove it because they don’t understand that you can create scopes like that


    {
        let foo = 1
    };
    // foo is undefined here




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: