0

For your average vanilla javascript project, how often do you use function with the function keyword or arrow functions? Is it okay to use more one side and less the other? Or vise versa? Or only use arrow functions? I mean more in a job type setting not for personal projects. In all honesty I do mostly like to write functions with the function keyword, but i'm not sure whats the best way to do it

Anything that works.

  • If you need access to `this`, use a standard `function() {}`. Normal functions are also good for hoisting. This means they can be referenced "before they are declared". The functions are moved (hoisted) to the top of the script when executed. Else, you can use arrow (aka lambda) functions `() => {}`. – Mr. Polywhirl Jul 27 '23 at 19:46
  • Use whichever one is appropriate for your needs. If it's a simple one-line evaluation, an arrow function is usually easiest. If you need to preserve `this`, use an arrow function. If it's an event listener where `this` should be the target, use a regular function. – Barmar Jul 27 '23 at 19:47
  • 1
    In most other situations, it doesn't matter and use whatever you like. – Barmar Jul 27 '23 at 19:47

0 Answers0