• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

167
Vistas
Why do we sometimes invoke a function and sometimes not in JS?

This is what confuses me alot: Sometimes we invoke a function and sometimes we do not.

To make this more clear:

We make two functions called getString and makeUpperCase:

function getString(string) {
  return string
}

function makeUpperCase(neutralString) {
  return console.log(getString(neutralString).toUpperCase())
}

makeUpperCase("Books.") // Prints BOOKS.

Here i just made a function called getString, it returns a parameter called string. Then in makeUpperCase function i invoke getString with "Books" as an argument, which will log the argument with UPPERCASE letters. At the end we invoke makeUpperCase function so it will log the text to the console.

Suppose we want to make a promise for an example.

This is just an example:

function executor(resolve, reject) {
  resolve("Promise status: resolved")
}

const promise = new Promise(executor)

I am pretty sure most of the people write promises a different way, however this is how i write the promise.

Here we create the promise, but we do not invoke the function, like we just pass the function executor without invoking it.

Like why? I am not sure if i get the point of sometimes invoking a function and sometimes not. What exactly is the point here?

about 3 years ago · Juan Pablo Isaza
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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda