This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Promise.resolve()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Itโ€™s been available across browsers since โจ2015๋…„ 7์›”โฉ.

Promise.resolve(value) ๋ฉ”์„œ๋“œ๋Š” ์ฃผ์–ด์ง„ ๊ฐ’์œผ๋กœ ์ดํ–‰ํ•˜๋Š” Promise.then ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ๊ฐ’์ด ํ”„๋กœ๋ฏธ์Šค์ธ ๊ฒฝ์šฐ, ํ•ด๋‹น ํ”„๋กœ๋ฏธ์Šค๊ฐ€ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค. ๊ทธ ๊ฐ’์ด thenable(์˜ˆ, "then" ๋ฉ”์†Œ๋“œ ๊ฐ€ ์žˆ์Œ)์ธ ๊ฒฝ์šฐ, ๋ฐ˜ํ™˜๋œ ํ”„๋กœ๋ฏธ์Šค๋Š” ๊ทธ thenable์„ "๋”ฐ๋ฅด๋ฉฐ", ๊ทธ ์ตœ์ข… ์ƒํƒœ๋ฅผ ์ทจํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ๋ฐ˜ํ™˜๋œ ํ”„๋กœ๋ฏธ์Šค๋Š” ๊ทธ ๊ฐ’์œผ๋กœ ์ดํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์ด ํ•จ์ˆ˜๋Š” ํ”„๋กœ๋ฏธ์Šคํ˜•์˜ ๊ฐ์ฒด(๋ฌด์–ธ๊ฐ€๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ํ”„๋กœ๋ฏธ์Šค๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ํ”„๋กœ๋ฏธ์Šค ๋“ฑ)์˜ ์ค‘์ฒฉ๋œ ๋ ˆ์ด์–ด๋ฅผ ๋‹จ์ผ ๋ ˆ์ด์–ด๋กœ ํŽผ์นฉ๋‹ˆ๋‹ค.

๊ฒฝ๊ณ : ์ฃผ์˜: ์Šค์Šค๋กœ๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” thenable ์—์„œ Promise.resolve ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค. ์ด๋Š” ๋ฌดํ•œํžˆ ์ค‘์ฒฉ๋œ ํ”„๋กœ๋ฏธ์Šค๋ฅผ ํŽผ์น˜๋ ค๊ณ ํ•˜๋ฏ€๋กœ ๋ฌดํ•œ ์žฌ๊ท€๋ฅผ ์œ ๋ฐœํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. Angular ์—์„œ async Pipe ๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•œ ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์—ฌ๊ธฐ์—์„œ ํ™•์ธํ•˜์„ธ์š”.

์‹œ๋„ํ•ด ๋ณด๊ธฐ

const promise1 = Promise.resolve(123);

promise1.then((value) => {
  console.log(value);
  // Expected output: 123
});

๊ตฌ๋ฌธ

js
Promise.resolve(value);

ํŒŒ๋ผ๋ฏธํ„ฐ

value

์ด Promise์— ์˜ํ•ด ๊ฒฐ์ •๋˜๋Š” ์ธ์ˆ˜. Promise ๋˜๋Š” ์ดํ–‰ํ•  thenable ์ผ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐ˜ํ™˜ ๊ฐ’

์ฃผ์–ด์ง„ ๊ฐ’์œผ๋กœ ์ดํ–‰๋œ Promise ๋˜๋Š” ๊ฐ’์ด promise ๊ฐ์ฒด์ธ ๊ฒฝ์šฐ, ๊ฐ’์œผ๋กœ ์ „๋‹ฌ๋œ promise.

์„ค๋ช…

์ •์  Promise.resolve ํ•จ์ˆ˜๋Š” ์ดํ–‰๋œ Promise ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ

์ •์  Promise.resolve ๋ฉ”์†Œ๋“œ ์‚ฌ์šฉ

js
Promise.resolve("Success").then(
  function (value) {
    console.log(value); // "Success"
  },
  function (value) {
    // ํ˜ธ์ถœ๋˜์ง€ ์•Š์Œ
  },
);

๋ฐฐ์—ด ์ดํ–‰

js
var p = Promise.resolve([1, 2, 3]);
p.then(function (v) {
  console.log(v[0]); // 1
});

๋˜ ๋‹ค๋ฅธ Promise ์ดํ–‰

js
var original = Promise.resolve(33);
var cast = Promise.resolve(original);
cast.then(function (value) {
  console.log("value: " + value);
});
console.log("original === cast ? " + (original === cast));

// ๋กœ๊ทธ ์ˆœ์„œ:
// original === cast ? true
// value: 33

๋กœ๊ทธ์˜ ์ˆœ์„œ๊ฐ€ ๋ฐ˜๋Œ€์ธ ์ด์œ ๋Š” then ํ•ธ๋“ค๋Ÿฌ๊ฐ€ ๋น„๋™๊ธฐ๋กœ ํ˜ธ์ถœ๋˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์—์„œ then ์ด ๋™์ž‘ํ•˜๋Š” ๋ฐฉ์‹์— ๋Œ€ํ•ด ํ™•์ธํ•˜์„ธ์š”.

thenable ์ดํ–‰ ๋ฐ ์˜ค๋ฅ˜ ๋ฐœ์ƒ

js
// thenable ๊ฐ์ฒด ์ดํ–‰
var p1 = Promise.resolve({
  then: function (onFulfill, onReject) {
    onFulfill("fulfilled!");
  },
});
console.log(p1 instanceof Promise); // true, ๊ฐ์ฒด๋Š” Promise ๋กœ ๋ณ€ํ™˜๋จ

p1.then(
  function (v) {
    console.log(v); // "fulfilled!"
  },
  function (e) {
    // ํ˜ธ์ถœ๋˜์ง€ ์•Š์Œ
  },
);

// thenable ์ด ์ฝœ๋ฐฑ ์ด์ „์— ์˜ค๋ฅ˜๋ฅผ throw
// Promise ๊ฑฐ๋ถ€
var thenable = {
  then: function (resolve) {
    throw new TypeError("Throwing");
    resolve("Resolving");
  },
};

var p2 = Promise.resolve(thenable);
p2.then(
  function (v) {
    // ํ˜ธ์ถœ๋˜์ง€ ์•Š์Œ
  },
  function (e) {
    console.log(e); // TypeError: Throwing
  },
);

// thenable ์ด ์ฝœ๋ฐฑ ์ดํ›„์— ์˜ค๋ฅ˜๋ฅผ throw
// Promise ์ดํ–‰
var thenable = {
  then: function (resolve) {
    resolve("Resolving");
    throw new TypeError("Throwing");
  },
};

var p3 = Promise.resolve(thenable);
p3.then(
  function (v) {
    console.log(v); // "Resolving"
  },
  function (e) {
    // ํ˜ธ์ถœ๋˜์ง€ ์•Š์Œ
  },
);

๋ช…์„ธ

Specification
ECMAScriptยฎ 2026 Language Specification
# sec-promise.resolve

๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ

ํ•จ๊ป˜ ๋ณด๊ธฐ