Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!