loading...

re: Javascript(ES6) Arrow Functions in a simple way: VIEW POST

FULL DISCUSSION
 

So I'm not convinced with defining functions with const you claim it's shorter - but that's because you've define the function version in a very odd way in your example.

const sayHello = (firstName,lastName) => { // 41 characters

Compared with

function sayHello(firstName,lastName) { // 39 characters

Plus I know the second one is a function. The first one is a const, not hoisted so I have to start caring about order and reading deep into the line to realise it is a function.

For me, the reason to use an arrow function is for capturing this or for defining an anonymous inline function:

   someArray.filter(a=>a.id.startsWith('$')) // this IS shorter and clearer
 

It's just a simplistic way to present an anonymous function the goal was to explain the arrow functions without talking about it in very detailed way but thanks for the reply.

code of conduct - report abuse