Why is {object promise} popping up when a function returns a number? I need it to return data


I am not sure why “[object promise]” pops up in this case. I have tried to get help but can’t figure it out.

let inputFile = convertToFile() + ' <-- Data';

And then here is the function.

async function convertToFile() {
    const fileInput = document.getElementById('filedata');
    const file = fileInput.files[0];
    const reader = new FileReader();

    return new Promise((resolve, reject) => {
        reader.onload = function(event) {
            const buffer = event.target.result;
            const hexString = Array.from(new Uint8Array(buffer))
                .map(byte => byte.toString(16).padStart(2, '0'))
                .join('');
            resolve(hexString);
            console.log(hexString);
        };

        reader.onerror = function() {
            reject(new Error('Error reading file'));
        };

        if (file) {
            reader.readAsArrayBuffer(file);
        } else {
            reject(new Error('No file selected'));
        }
    });
}

I am not sure why this doesn’t work but it should return the text. Please help I am desperate.

I tried to replace it with another function and it worked fine. The problem is it returns “[object promise]”

Furthermore, I have also tried “await”

let inputFile = await convertToFile() + ' <-- Data';