DEV Community

Ed Stokes
Ed Stokes

Posted on

Difference between Arrow Functions and Regular Functions

The first and most obvious difference is the Syntactical difference.
Arrow functions have a type of shorthand that can lead to less lines of code. The use of parenthesis can be ommited. Digging deeper into Arrow functions you will find other differences that can have an effect on the way the code is executed. The execution context is dynamic in a regular function. The execution context in an Arrow function is lexically. This difference has a direct effect on the way the value of "this" is assigned. The value of "this" in a regular function is based on how the funcition was invoked. An Arrow function does not define its execution context resulting in "this being defined in the scope of the function. This difference would make a regurlar function a better choice for methods. The difference in execution context also has an effect when using functions as constructors you can not use an Arrow fucntion as a constructor. This will result in a TypeEror.

Top comments (0)