Function VS Arrow Function
What I’ve found difficult within my coding journey is understanding the differences between a function vs an arrow function. Is there a difference? Well, there is a bunch of differences but lets look at a small example first to see what makes an arrow function and what is a regular function.
In this example we declared a function named greetings that has an argument of person and having that function return a string with that argument within it.
In this bit of code we have a variable assigned with the name greeting that creates an arrow function with the argument of person within it returning a string. That is how we declare a regular function vs an arrow function. So why would anyone do this? Well with the regular function when we use the value of this is using in a method invocation which the value of this is the object owning the method.
Within an arrow function, this is not defined within its own execution context, this within the arrow function resolves lexically.
With arrow functions you no longer have to create a callback or use self, this within arrow functions help react become a much easier and enjoyable experience with React.
This was a very short read but thank you for taking your time to read this! I appreciate it!