Regular functions created through function declarations / expressions are both constructible and callable. ... Arrow functions (and methods) are only callable i.e arrow functions can never be used as constructor functions. Hence, they can never be invoked with the new keyword.
// Arrow function vs function
// Function in JavaScript
function regular(){
console.log("regular function");
}
regular(); //regular function
// Arrow Function
const arrow = () => console.log("Arrow function");
arrow(); //Arrow function
// currently common pattern
var that = this;
getData(function(data) {
that.data = data;
});
// better alternative with arrow functions
getData(data => {
this.data = data;
});
// Using function expression syntax
const addNums = function(numOne, numTwo) {
return numOne + numTwo;
};
// Using new arrow function syntax
const addNums = (numOne, numTwo) => {
return numOne + numTwo;
};