Let’s check out the conventional js operate.
operate myName(identify){
console.log(identify);
}
myName("Sujith")
The above operate will be written in arrow operate as,
const myName = (identify) => {
console.log(identify)
}
myName("Sujith")
In arrow operate we assign the operate physique to a variable, and we go the arguments by means of the parenthesis between =
and =>
eg:= (identify) =>
And the physique of the arrow operate is available in between the curly braces {}
.We are able to use return key phrase to return a worth within the operate.
Arrow operate with one argument.
const myName = identify => {
console.log(identify)
}
myName("Sujith")
If an arrow operate is having just one argument, then we are able to exclude the parenthesis whereas passing the argument.= identify =>
Arrow operate with single assertion.
const myNumber = nbr => nbr * 5
console.log(myNumber(5))
If an arrow operate has solely a single assertion to return or execute, then we are able to exclue the {}
and write them as => nbr * 5
. It mechanically returns that assertion after =>
and we need not use return key phrase.