Can we use an arrow function to create objects in JavaScript?
The answer is - NO
Unlike other functions, an Arrow function does not have the prototype object and is set to undefined.
Whenever we create objects from a function, newly created objects are linked to the function's prototype object. Since an arrow function prototype object is undefined, it can not be used as a constructor.
The following code gives an error.
var City () = {} // arrow function
console.log(City.prototype); // undefined
var b = new City(); // error
Remember that an arrow function can not be used as a constructor.
Download
0 formats
No download links available.
Why arrow function can not be used to create object | Arrow function in JavaScript | NatokHD