Promise In JavaScript – JavaScript Promise

In this blog you are going to learn promises in JavaScript. JavaScript promise is one of the important concept in JavaScript. Promises are used to perform asynchronous operations.

What Is Promise In JavaScript ?

A JavaScript Promise object can be:

  • Pending
  • Fulfilled
  • Rejected

What is a Promise in JavaScript?

In JavaScript, a Promise is an object representing the eventual completion or failure of an asynchronous operation.

What Is Synchronous In JavaScript ?

What Is Asynchronous In JavaScript ?

Important Points Regarding Promises

  • In JavaScript, a promise is a good way to handle asynchronous operations. It is used to find out if the asynchronous operation is successfully completed or not.
  • In JavaScript, a promise starts in a pending state. That means the process is not complete. If the operation is successful, the process ends in a fulfilled state. And, if an error occurs, the process ends in a rejected state.
  • For example, in JavaScript when you request data from the server by using a promise, it will be in a pending state. When the data arrives successfully, it will be in a fulfilled state. If an error occurs, then it will be in a rejected state
  • In JavaScript Promise, the then() method is used with the callback when the promise is successfully fulfilled or resolved.
  • In JavaScript Promise, the catch() method is used with the callback when the promise is rejected or if an error occurs

Source Code Of Promise In JavaScript


<!doctype html>
<meta charset="utf-8">
<title>Untitled Document</title>

		let p = new Promise(function(resolve, reject){
				let a = 1 + 2;
			if(a == 3)
		let onFulFil = (msg) => {
			document.write(msg + " - Promise FulFilled..");
		let onReject = (msg) => {
			document.write(msg + " - Promise Rejected..");
//		p.then((msg) => {
//			document.write(msg + " - Promise FulFilled..");
//		}).catch((msg) => {
//			document.write(msg + " - Promise Rejected..");
//		})
//		console.log(p);

Download Notes Of This Blog From the link given below

Download Source Code of This Blog From the link given below

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *