DEV Community

Discussion on: What’s your alternative solution? Challenge #45

 
miketalbot profile image
Mike Talbot ⭐

So arrow functions make a class that captures the current "this" and provide it through to the inner function. It's not a massive cost, but it's additional to the cost of calling a function in both memory and instructions. It makes total sense if you need the "this" and indeed all functions declared in the body of another create a class to carry around the bound closure variables - but there is no such cost for a globally defined function.

Declaring any const requires that the code is executed before using the variable.

This works:


     doSomething() 

     function doSomething() { console.log('ok'); }

This does not:


     doSomething();
     const doSomething = ()=>console.log("Nope!");