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

174
Vistas
await IIFE result vs separate async function

I have been refactoring some legacy code and found the following example:

    // inside other function
    const isTriggerValid = await (async () => {
        try {
            const triggers = await db.any(getTriggerBeforeBook, { paramId });
            if (!triggers || triggers.length === 0) {
                return false;
            }

            return true;
        } catch (e) {
            logger.error(e);
            return false;
        }
    })();

and I'd like to ask, what is the point between it, and the code below?

   const isTriggerValid = async (paramId) => {
     try {
        const triggers = await db.any(getTriggerBeforeBook, { paramId });
          if (!triggers || triggers.length === 0) {
              return false;
          }
        return true;
     } catch {
        return true;
     }
   }

And then invoking it with const trigger = await isTriggerValid(paramId) ?

I know absolutely for sure that this keyword hasn't been used in it.

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

0

The main difference would be that in the old version isTriggerValid would be the functions result and in the new one it's a function and the result would be called trigger. Other than that both are invoking the same function.

Regarding your concern about this. In both variants it's an arrow-function inheriting the parent-context so even if it was used it would be the same in both.

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