DEV Community

ana
ana

Posted on

Arrow Function

Image description

Before explain Arrow function you should learn EcmaScript(6)
and learn about that.

So.. I just explain a little about that: is a JavaScript standard intended to ensure the interoperability of web pages across different browsers.

well, now we arrived to ArrowFunction.
as you know ecmaScript has multiple versions, in last version(5) arrowFunction was somthing like that:

const function1 = function(x, y) {
   return x * y;
}
Enter fullscreen mode Exit fullscreen mode

But in the next version arrowFunction in ecmaScript changed:

const function1 =(x, y)=> x * y;
Enter fullscreen mode Exit fullscreen mode

so whenever you see this symbol =()=> in javaScript its mean Arrow Function!!

this is very important topic in java script, if one day you want to learn React you need to know what is arrowFunction and how should use from it.

as you see, we declare a variable with const and gave a name to it and then after equal symbol = we gave our arguments in the parentheses and use from this =>, after this line we just return our output, remember this, it doesn't matter to use return word or not, but in React!! is so important.

Top comments (4)

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

All you need to see is: => - it is the arrow from which 'Arrow functions' get their name.

const a = x=>x
console.log(typeof a)  // 'function'

console.log( (i=>i)(3) )  // 3
Enter fullscreen mode Exit fullscreen mode

Also, the arrow function has never changed. Your first example shows a function expression, not an arrow function.

Collapse
 
anateotfw profile image
ana

hmmm, this is new topic for me, thank you.

Collapse
 
codeofrelevancy profile image
Code of Relevancy

Great article

Collapse
 
anateotfw profile image
ana

thank you!!!