0

My friend told me I should use either function() or arrow functions but not together in a single project since the programming style should be unified and it is not neat to see function() and arrow functions mixing together. Is that true? I feel like sometimes arrow function is better while sometimes old-school function is better.

legenddaniel
  • 698
  • 2
  • 9
  • 17
  • 2
    Sometimes a `function` is required. Sometimes an arrow function allows for the most concise way of writing things (without `const that = this` shenanigans). Past that, it's only a style choice. You can choose to prefer one or the other whenever possible, or you can choose to use both – CertainPerformance Jan 21 '20 at 00:52
  • @CertainPerformance I checked the Q&A you provided before I asked this question. What my friend means is: if you found only one function that need to be 'upgraded' to arrow function you have to 'upgrade' all functions in your .js, or keep everything unchanged, to keep your codes neat and tidy. – legenddaniel Jan 21 '20 at 01:21
  • It's opinion-based - a style choice (off-topic). Personally, I'd prefer to use arrow functions everywhere, but it's nowhere close to a rule that there's a consensus on – CertainPerformance Jan 21 '20 at 01:35
  • @CertainPerformance Thx! – legenddaniel Jan 21 '20 at 02:25
  • 2
    Understanding what arrow functions provide and why they were introduced is important in answering this question. Arrow functions are syntactically cleaner but also do not create bindings for `this`, `arguments`, `super`, or `new.target` keywords. If you don't need to create a new `this` context and don't need the previously defined bindings, go with arrow functions. Otherwise, use standard function declaration. It all depends. – dillon Jan 21 '20 at 03:04

0 Answers0