Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
Is it possible to pass multiple arguments to JS Promise.resolve()?

I am trying to learn promises in JS. I have a function that computes the sum or difference of two numbers depending on operation provided by the user.

function compute(firstNum, secondNum, operation) {
    let result = null;
    operation === "+"
        ? (result = firstNum + secondNum)
        : operation === "-"
        ? (result = firstNum - secondNum)
        : console.log("operation not supported");
    return result;
}

I am trying to define a function that returns a promise which does essentially the same thing as the compute function above.

let operators = {
    "+": function (a, b) {
        console.log(a + b);
    },
    "-": function (a, b) {
        console.log(a - b);
    },
};

function calculate(firstNum, secondNum, operation) {
    return new Promise((resolve, reject) => {
        if (operation === "+" || operation === "-")
            resolve([firstNum, secondNum, operation]);
        else reject(new Error("operation not supported"));
    });
}

calculate(5, 51, "-")
    .then((returnedArr) => {
        let answer = operators[returnedArr[2]](returnedArr[0], returnedArr[1]);
    })
    .catch((err) => {
        console.log(err);
    });

Is it possible to pass more than one argument to resolve() inside a promise?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!