As you can see the function is hoisted and can be called earlier in the program. Also, the function can be called with the new keyword, because functions are objects. Now, these characteristics are different compared to arrow functions. So, let’s discuss the awesome arrow functions.
Arrow functions are specialized, giving them different characteristics from standard functions. Unlike standard functions, they are not hoisted and can’t be instantiated (called with the new keyword). Lastly, they are lexically scoped. This is a defining factor so let’s explain lexical scoping.
Lexical scoping means that the functions do not create a new function scope when defined. Now, the scope defines where variables exist. The scope is simply a block scope and will not change the context of “this”. Now, “this” refers to the current function or object you’re in at the time.; if you use a standard function, “this” will refer to the new standard function. As a result, arrow functions are often the best choice for anonymous functions or for writing functions that are very explicit. Here’s an example showcasing all their characteristics.
As you can see, they are very beneficial shortening the amount of code you have to write significantly. Also, they maintain the context correctly; an important feature which allows for the writing of callback functions that are smaller more performant. As you can see, it also throws an error if you try to instantiate an arrow function, which allows you to keep unintended side effects out of your program.