Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
javascript function returning function instead of float/object

i have a function where im returning some html element, before i return it, if i console.log() it it outputs the numerical value eg. 1234... however its typeof() is "object" even though i have parseFloated() it... after returning it, it returns as a typeof() as function... im trying to pass the return value through to another function, can someone please explain to me what is going wrong? how do i keep the return value as an object or float rather then a function so i can then pass it?

async function checkPrice(page) {
    await page.reload();
    await page.waitForNavigation();
    await page.waitForTimeout(2000); // network idle2 not working... this is sufficient

    var html = await page.evaluate(() => {
        const buyTag = document.querySelectorAll(".MuiButton-root.MuiButton-contained.MuiButton-containedPrimary.MuiButton-sizeMedium.MuiButton-containedSizeMedium.MuiButton-disableElevation.MuiButtonBase-root.color-tertiary.css-k5syhx .css-gmuwbf");

        let prices = [];

        buyTag.forEach((tag) => {  

            if(tag.innerHTML[0] === '$' ) {
                var string = tag.innerHTML;
                var float  = parseFloat(string.replace(/[^0-9.-]+/g, ''));
                if(prices.length < 1) {
                   prices.push(float)
            }}
        });
        return prices
    });
    // console.log(html) returns 1234, typeof() is obj here
    return html
}
// console.log(html) returns a function here
async function priceUpdate(html) { 

    let new_price = []; 
    let old_price = [];

    if(new_price.length < 1) {
        new_price.push(html);
    }
    if(new_price.length > 0) {
        old_price.pop();
        old_price.push(new_price);
        new_price.pop();
        new_price.push(html);
    }
    if(parseFloat(new_price[0]) != 
    parseFloat(old_price[0])) {
        console.log('lowest price changed from: $' + old_price + ' to: ' + '$ ' + new_price);
    }
    else {
        console.log('current price: $' + old_price);
    };
}

async function monitor() {
    let page = await configureBrowser();
    for(var i=0; i=1000; i++) {
        await checkPrice(page);
        await priceUpdate(html);
    }}

monitor()
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda