Suggest an editImprove this articleRefine the answer for “How does resolve differ from reject?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)`resolve(value)` signals that the operation **completed successfully**, moving the promise to **fulfilled**, while `reject(reason)` signals that the operation **failed**, moving the promise to **rejected**. **Key point:** both move the promise from `pending` to a final (settled) state, but down different result "branches".Shown above the full answer for quick recall.Answer (EN)Image## Short answer - `resolve(value)` - signals that the operation **completed successfully** → the promise becomes **fulfilled**. - `reject(reason)` - signals that the operation **completed with an error** → the promise becomes **rejected**. Both move the promise from `pending` → to a **final (settled)** state, but down different result "branches". ## Example ```javascript const promise = new Promise((resolve, reject) => { const success = Math.random() > 0.5; if (success) { resolve('Everything went well'); } else { reject('An error occurred'); } }); promise .then(result => console.log('then:', result)) .catch(error => console.log('catch:', error)) .finally(() => console.log('finally')); ``` Possible output: ```javascript then: Everything went well finally ``` or ```javascript catch: An error occurred finally ``` ## How they work | Method | What it does | Promise state | What it triggers | |---|---|---|---| | `resolve(value)` | Completes the promise successfully, passes the `value` | **fulfilled** | `.then(value => …)` | | `reject(reason)` | Completes the promise with an error, passes the `reason` | **rejected** | `.catch(error => …)` | After one of them is called: - the promise is "settled", - a further call to `resolve` or `reject` is ignored. ## Example: resolve ```javascript const promise = new Promise((resolve) => { setTimeout(() => { resolve('Data received!'); }, 1000); }); promise.then(result => console.log(result)); ``` After 1 second: ```javascript Data received! ``` The promise moved to the **fulfilled** state. ## Example: reject ```javascript const promise = new Promise((resolve, reject) => { setTimeout(() => { reject('Network error'); }, 1000); }); promise.catch(error => console.error(error)); ``` After 1 second: ```javascript Network error ``` The promise moved to the **rejected** state. ## Important: the state can only change once ```javascript const promise = new Promise((resolve, reject) => { resolve('OK'); reject('Error'); // ignored }); promise.then(console.log).catch(console.error); ``` After the first call (`resolve`) the promise became **fulfilled**, and the second call (`reject`) has no effect. ## Example: resolve with another promise If you pass **another Promise** to `resolve()`, the current promise **waits** for it to settle. ```javascript const inner = new Promise((resolve) => setTimeout(() => resolve('Inner result'), 1000)); const outer = new Promise((resolve) => resolve(inner)); outer.then(console.log); // logs "Inner result" after 1 sec. ``` This is called **promise unwrapping**. ## Handling the results ```javascript new Promise((resolve, reject) => { resolve('OK'); }).then(console.log); // OK new Promise((resolve, reject) => { reject('Error'); }).catch(console.error); // Error ``` ## Analogy > Think of a promise as a delivery: > > - `resolve` → the courier delivered the package (everything succeeded) > - `reject` → the courier called and said: "address not found" (error) ## SUMMARY | Method | State | What it passes | Handled where | Analogy | |---|---|---|---|---| | `resolve(value)` | fulfilled | The successful result | `.then()` | Package delivered | | `reject(reason)` | rejected | The error / rejection reason | `.catch()` | Courier could not deliver | | After the call | The promise becomes `settled` and cannot be changed anymore | - | - | - |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.