DEV Community

Discussion on: Share More JS / Avoid More BS

Collapse
 
vonheikemen profile image
Heiker • Edited

Something very curious happens in here. If you try this in the browser it gives you an error.

var counter = (function counterAdd() {

    let current = 0;

    return () => current = current + 1

}());

console.log(counterAdd);

Since the function has a name I would expect counterAdd to be available on scope but it isn't, it gives me a ReferenceError.

Collapse
 
bhankee profile image
Brad Hankee

Good Catch. My fault for posting late on Sunday night.... had a few codepens open I did and pulled from the wrong one.
Updated and all good now.