Why arrow function can not be used to create object | Arrow function in JavaScript

preview_player
Показать описание
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
var b = new City(); // error

Remember that an arrow function can not be used as a constructor.
Рекомендации по теме
Комментарии
Автор

Outstanding ❤, Thanks for restarting video tutorials again

vithalwadjec
Автор

Thanks for sharing Waiting for more such videos @Geek97

amitkrishna
join shbcf.ru