converting a normal function to arrow function

named function with multiple parameters in

code image

we are going to use a named function with multiple parameters (in this case two) to convert into arrow function, as it is probably the most common format.

How to convert this to arrow function :

code image

the first thing we need to do to convert an arrow function is completely remove the function keyword because with an arrow function this function keyword is assumed and now we need to assign it to a variable so we're just going to call that sum2. the reason we have to do this assignment here to a variable is because normal functions already create a variable of the name sum. In this case with the function keyword but since we no longer have the function keyword we now need to create our own variable to store this function and the only change that we need to make to convert this function syntax from here to an arrow function is to add in the arrow that denotes that these are our parameters on the left side here inside of the parentheses and then we have an arrow to denote that this is a function and then inside of the brackets .We put the actual function syntax that we're going to be using and now our sum2 and sum are both the exact same function just one uses the arrow syntax and the other uses a normal function.

Reducing furthur

code Image

we can go even further to reduce this code slightly more since as you can see we just have one line of code and it returns something this arrow functions can be changed so that we can remove this return completely and we can remove these curly braces and put everything on one line so if you do this everything after the arrow is assumed to be returned so this a + b is going to be returned because there's no brackets and there's no return statement so it just assumes that whatever comes after the arrow here is going to be returned from the function and this again is exactly the same as our normal function that we have defined at the top here but as you can see this is much more concise and easier to use.