Fri, Nov 15, 2019
Read in 1 minutes
What’s the meaning of “=>” (an arrow formed from equals greater than) in JavaScript?
“=>” This is called arrow function in JavaScript. This arrow function is a kind of substitute for the function keyword.
Consider, writing a function for addition of two numbers
var ADD=function(a,b){
return a+b;
}
// The same can be written with arrow function .
var ADDArrowFunc =(a,b)=>{
return a+b;
}
Here the difference is, parameters have to be written in front of the arrow function.
Arrow Function with Single Parameter :
For the single parameter, the parentheses are optional.
var double=a=>{
return a+a;
}
one line function expression:
For online function expression, the return statement and curly brackets are optional.
- var Multiply =a=>a*a;