what is promise in javascript

var promise = new Promise(function(resolve, reject) {
  // do some long running async thing…
  if (/* everything turned out fine */) {
    resolve("Stuff worked!");
  else {
    reject(Error("It broke"));

  function(result) { /* handle a successful result */ },
  function(error) { /* handle an error */ }
	A Promise is a proxy for a value not necessarily known when the promise is created. 
    It allows you to associate handlers with an asynchronous action's eventual success 
    value or failure reason.
let promise = new Promise((resolve , reject) => {
    .then((res) => {
      // successfully got data
    .catch((err) => {
      // an error occured
});var str = "Howdy GeeksforGeeks"
var geek = {
  book: "harrypotter",
  price: "2000"
var geek2 = [10, 20, 30];
console.log("geek (log) = ", geek);
console.log("geek2 (log) = ", geek2);

// Prints only string as dir() takes 
// only one parameter. 
console.dir("geek2 (dir) = ", geek2);We use promise to make a  AsyncFunction, cose simetime we have to wait that function give 
us some result.
Example, if we use ajax we have await ajax data or statament.
Make a simple example.
var asyncronus_function= (number)=>
			return new Promise( (accept, reject)=>
this function return a promise Object, thet required a function executor
this functions (accept, reject) are defined in the executor 
function, that was needed in promise constructor.
Syntax: new Promise (executor)
executor= (accept, reject) =>{}

if function end well we return a accept(), otherwise reject()
Let complete asyncronus_function
var asyncronus_function= (number)=>
			return new Promise( (accept, reject)=>
				return accept("my first async");
				return reject("my first async error")

if it dont return any of this 2 function, Promise state is [PENDING] ,
if return accept is [RESOLVED]  end if return reject is [REJECTED]
how we can retrieve accept or reject?
there is two methods really important, that we have to consider afther we call this function
1) .then(function(error){}) is call when promise state is [RESOLVED]
2) .error(function(error){}) is call when promise state is [REJECTED]
3) do nothing if [PENDING]
let call asyncronus_function()!!! 
    	}).catch(error => 
if  MY_NUMBER> 10 ,asyncronus_function print data : OUTPUT my first async
if MY_NUMBER<10 , asyncronus_function print error : OUTPUT my first async error
HOPE it halp and have a nice day! 

//Promise to load a file...
//use with openFile(url, fCallback);
//fCallback(fileContents){ //do something with fileContents}
const loadFile = url => {
    return new Promise(function(resolve, reject) {
        //Open a new XHR
        var request = new XMLHttpRequest();
        request.open('GET', url);
        // When the request loads, check whether it was successful
        request.onload = function() {
            if (request.status === 200) {
                // If successful, resolve the promise
            } else {
                // Otherwise, reject the promise
                reject(Error('An error occurred while loading image. error code:' + request.statusText));
const openFile = (url, processor) => {
    loadFile(url).then(function(result) {
        function(err) {
};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

Also in JavaScript: