Google News
logo
Full Stack Developer - Interview Questions
Why should arrow functions not be used in ES6?
One of the most popular features of ES6 is the "arrow functions" (also known as "fat arrow functions"). Arrow functions are a new way to write concise functions. Arrow functions offer a compact alternative to traditional function expressions, but they have limitations and cannot be used in every case.
 
The following is an ES5 function :
function timesTwo(params) {
        return params * 2
     }
timesTwo(5);  // 10
The same function can also be expressed as an arrow function in ES6 as follows :
var timesTwo = params => params * 2
timesTwo(5);  // 10
Differences & Limitations :
* Has no bindings to 'this' or 'super', so it shouldn't be used as a method.
* Has no new.target keyword.
* The call, apply, and bind methods are not suitable since they rely on establishing scope.
* Not suitable for use as constructors.
* Not possible for an arrow function to use the yield keyword within its body, etc.
Advertisement