Table of contents
Hello everyone, hope you are all doing well. My name is Surya L, and the aim of this blog is to teach you How to Write Arrow Functions➡ with Parameters in JavaScript.
Arrow Functions➡ with Parameters:
For Arrow Function Basics read here.
Like a regular function, you can pass arguments into an arrow function.
const thripler = (item) => item * 3;
thripler(4);
//thripler(4) would return the value 12.
If an arrow function has a single parameter, the parentheses enclosing the parameter may be omitted.
const thripler = item => item * 3;
It is possible to pass more than one argument into an arrow function.
const multiplier = (item, multi) => item * multi;
multiplier(4, 2);
//multiplier(4, 2) would return the value 8.
Example1:
const myConcat = (arr1, arr2)=>{
return arr1.concat(arr2);
};
console.log(myConcat([1, 2], [3, 4, 5]));
In the above Arrow Function (arr1,arr2) are the two parameters and
return arr1.concat(arr2); would add both array arr1 and arr2.
The Output of above code is 👇
[ 1, 2, 3, 4, 5 ] Thanks for reading the blog. Do let me know what you think about it.
You can connect me with Showwcase Twitter Blog GitHub Contact Me
Reference: I learned this topics in FreeCodeCamp which I explained in minified version