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

204
Visualizações
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 4 years ago · Juan Pablo Isaza
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