Estoy tratando de hacer una función de devolución de llamada que tenga una función anónima anidada en su interior. Mi código se parece a esto:
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) Pero la función anónima nunca se inicia. El segundo console.log nunca se ejecuta y no puedo entender por qué.
NUEVA RESPUESTA: GRACIAS POR COMENTARIOS
// 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");VIEJO: ¡Asegúrate de declarar las funciones y luego las llamas!
// 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)