How to pass multiple arguments to Promise.resolve

I am trying to learn JS Promise. I have the following function which returns either the sum or difference of two numbers depending on the 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 tried to use Promise to achieve the same thing with the following codes.

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) => {



Would it be possible to pass multiple arguments into Promise.resolve instead of an array?

Right, I’m no expert on Promise, but isn’t what you pass to resolve effectively what you are returning? How do you return more than one item? You’d have to put them in an array or an object.

I settled with passing an array to resolve after a failed attempt to pass more than one arguments. My only displeasure with this method is that in certain scenario, the returned array will have to contain data of different type, which make working with the array cumbersome.

I don’t understand that. If they are different types in the array, then they would be different types out of the array. There would be no difference between resolving multiple variables (if that were possible) or resolving them in an array (or object) and pulling them out of the array. They will be the exact same data whether by value or by reference. I can’t even imagine a difference in practical terms. The only difference I can see is conceptual, and that’s just a matter of changing how we think.

Just put them in an object.

 resolve({ firstNum, secondNum, operation });

That way it’s also more readable.

Yes, there is something to be said for using objects. The OP mentioned arrays, and his percieved concerns would be the same with objects, but I would use an object in this case. It’s more explicit to label your data that way.