Resolving a Promise [object Promise]

I’m struggling to understand why a function I’m calling console logs the correct information inside of my function, but returns an [object Promise] outside.
Please let me know what I’m missing here.

// --- JSW function --- //
export function discountRate(fee1, fee2, fee3) {
    try {
        var fee1 = fee1;
        var fee2 = fee2;
        var fee3 = fee3;
        let total = fee1 + fee2 + fee3
        return total
    } catch (e) {
        console.log(e)
    }
}
// --- Page Code --- //
// Async function that calls a JSW function discountRate()
async function getDiscount(fee1, fee2, fee3) {
    const result = await discountRate(fee1, fee2, fee3);
    return result
}
// --- Page Code --- //
// Set fees for getDiscount() function
let fee1 = 5
let fee2 = 10
let fee3 = 5
// Set variable discount to the result of getDiscount() function
const discount = getDiscount(fee1, fee2, fee3).then(function (result) {
    // Returns 20
    console.log("discount result inside function: " + result)
    return result
})
// Returns [object Promise]
console.log("discount result outside function: " + discount) 

To further this. If I move the JSW code into the page code everything works. console.log(discount) returns 20

I know this is old.

I am no expert, but…
I had a similar problem inside backend code. The “log” message was returning [{}] inside the logs. Then I realized that in fact it was returning a “object Promise”.

In my case, I think I solved it waiting for the promise to resolve BEFORE loggin the result.
So in your case, I would try:

  1. Make the function from which you are calling the getDiscount function an “async” function.
  2. Put an “await” before calling the getDiscount function:
const discount = await getDiscount(fee1, fee2, fee3).then(function (result)
{
    // Returns 20
    console.log("discount result inside function: " + result);
    return result
});
// Hopefully, it will return "20".
console.log("discount result outside function: " + discount) 
  1. Or… do not declare “getDiscount” async.