Answers for "promise definition in javascript"

1

promise definition in javascript

A promise is an object that may produce a single value sometime in the future: either a resolved value, or a reason that it's not resolved (e.g., a network error occurred)
Posted by: Guest on June-24-2021
2

what is promise in javascript

Promises make async javascript easier as they are easy to use and write than callbacks. Basically , promise is just an object , that gives us either success of async opertion or failue of async operations
Posted by: Guest on November-29-2020
0

making promises in js

getData()
    .then(data => console.log(data))
    .catch(error => console.log(error));
Posted by: Guest on July-28-2020
0

javascript promises

var posts = [
  {name:"Mark42",message:"Nice to meet you"},
  {name:"Veronica",message:"I'm everywhere"}
];

function Create_Post(){
  setTimeout(() => {
    posts.forEach((item) => {
      console.log(`${item.name} --- ${item.message}`);
    });
  },1000);
}

function New_Post(add_new_data){
  return new Promise((resolve, reject) => {
    setTimeout(() => {
     posts.push(add_new_data);
      var error = false;
      if(error){
        reject("Something wrong in </>, Try setting me TRUE and check in console");
      }
      else{
        resolve();
      }
    },2000);
  })
}

New_Post({name:"War Machine",message:"I'm here to protect"})
    .then(Create_Post)
    .catch(err => console.log(err));
Posted by: Guest on October-06-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language