What is Promise function in javascript?
Answers (1)
Add AnswerIn JavaScript, promises are used to handle asynchronous operations. They are simple to handle when dealing with several asynchronous activities when callbacks might lead to unmanageable code.
Prior to promises, events and callback functions were utilized, but they were restricted in functionality and resulted in unmanageable code.
Multiple callback functions would result in callback hell, resulting in unmanageable code. It is also difficult for any user to manage many callbacks at the same time.
Syntax :
var promise = new Promise(function(resolve, reject){ //do something });