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

276
Vistas
Nested anonymous function wont run (javascript)

I am trying to make a callback function that has an anonymous function nested inside. My code looks something like this:

    function submitGuess(guess) {
        if (guess.length === 5) {
            console.log("The guess was 5 letters");
            const postGuess = async () => {
                console.log("Anon function initiated")
                const res = await fetch(SOME_URL);
            }
        }
    }
    submitGuess(guess)

But the anonymous function never initiates. The second console.log never runs, and I can't figure out why.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

NEW ANSWER: THANKS FOR FEEDBACK

// declare the function
async function submitGuess(guess) {
    if (guess.length === 5) {
        console.log("The guess was 5 letters");
        const postGuess = async () => {
            console.log("Anon function initiated")
            const res = await fetch("url");
        };
        await postGuess(); // call the function
    }
}

submitGuess("input");

OLD: Make sure you declare the functions then you call them !!

// declare the function
function submitGuess(guess) {
    if (guess.length === 5) {
        console.log("The guess was 5 letters");
        postGuess(); // call the function
    }
}

// declare the function
const postGuess = async () => {
    console.log("Anon function initiated")
    const res = await fetch(SOME_URL);
}

submitGuess(guess)
about 4 years ago · Juan Pablo Isaza Denunciar
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