I don't see the beauty of ES6 arrow functions | Sololearn: Learn to code for FREE!

+3

I don't see the beauty of ES6 arrow functions

Hello guys i don't know if it's really awkward but the arrow function feel so intimidating and strange to me , i've been trying to understand it for over a week or so , can anyone explane it more clearly ?

11/26/2018 12:13:35 PM

Omar khaled

9 Answers

New Answer

+18

[ES6:] Cool stuffs - A big fat Arrow https://medium.com/front-end-hacking/es6-cool-stuffs-a-big-fat-arrow-c01e3d7b5357 Arrow Functions https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions https://www.sololearn.com/learn/JavaScript/2970/

+10

Omar khaled Have a nice Coding!;)👍😄🤓 https://www.sololearn.com/post/48576/?ref=app https://code.sololearn.com/WGNbcu840MY1/?ref=app

+8

A normal JavaScript function: function addition(a, b) { return a + b; } It could be written in variable function below: var addition = function (a, b) { return a + b; If written in ES6, arrow function: var addition = (a, b) => { return a + b; } For single statement return arrow function, It could also be written in shorthand below: var addition = (a, b) => a+b;

+6

Omar khaled Here an example, to love arrow functions! 😀👍😉 https://code.sololearn.com/WxEg6de0NtKy/?ref=app

+5

Declaring a function in a variable has advantages, and it is called a function expression (opposed to a function declaration). This type of function doesnt get invoked when the code is read and only when it is called, and it is very useful when using first class functions (passing a function as a parameter to another function), as well as other advantages.

+4

I saw a presentation once where the speaker said arrow functions were originally used to make presentations more clear. It was deadpanned (so, no idea if it was a joke; I don't remember if anyone laughed) but it felt like the tone was "because it's less clutter". I think I can find the presentation again (it was a really interesting list of JS feature quirks...though now...I think it might contain a significant amount of adult language), but anyway..just earmarking this Q&A so I have a bookmark for possible update.

+3

this is not a variable in fact. It's a constant. I should use const instead. e. g. const addition = (a, b) => a+b: Don't confuse it with JavaScript variables, in JavaScript, function can be declared as var or const too.

+2

[meta update] Found the presentation on Javascript WTF's; it does contain cursing so...your choice to watch or not. Kyle is writing some free-online books at http://YouDontKnowJS.com if you want to go that route instead. What the...JavaScript? [38:16] InfoQ, Kyle Simpson for Forward 2, "pulling out the crazy" from JavaScript https://www.youtube.com/watch?v=2pL28CcEijU&t=1151s "By the way that weird arrow syntax...that's ES6's new version of the function called an arrow function...but just to let you know arrow function is all so that people that make slides and write books can write less code. Really, that's its only purpose, so I put it on my slides so that my slides are shorter." It may be weary sarcasm :)

0

Calvin, why would we define the function for a certain variable what difference does it make , than defining the function in isolation from variables , thanks