Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda