DEV Community

Discussion on: Learn Javascript Functions

Collapse
 
loucyx profile image
Lou Cyx • Edited

Worth mentioning that nowadays you can use the Arrow function syntax, which makes your code way simpler. To illustrate I'll transform some of the functions in your post:

const sayHi = () => console.log("I like JavaScript");
const myFunction1 = () => (console.log("Hello world"), console.log(3 + 5));
const myFunction2 = number => number ** 2;
const myFunction3 = (number1, number2) => number1 + number2;
Enter fullscreen mode Exit fullscreen mode

Cheers!

Collapse
 
zahab profile image
Zahab Kakar

Thank you, Yes it worths but that is the ES6 concept and might confuse some beginners.

Collapse
 
loucyx profile image
Lou Cyx • Edited

I recently teach this to a few juniors, and they got it faster than the old version, mainly because is less verbose, look at it without syntax highlight:

function (number) { return number * 2 };
Enter fullscreen mode Exit fullscreen mode
number => number * 2;
Enter fullscreen mode Exit fullscreen mode

Arrow functions look more like value → result, while the old syntax is more like function (value) return result, which feels like more words to say the same. Still my point is not so much you should only show Arrow functions, my point is that you should show both. Nowadays arrow functions are used a lot, and if this is "learn JavaScript Functions", arrow functions should be included.

Cheers!

Thread Thread
 
zahab profile image
Zahab Kakar

Thanks for your comment, I just edited the article and added the arrow functions concept too :)