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

160
Visualizações
Is more or less efficient to use a stand alone function than a callback in JavaScript?

I'm new to JavaScript and recently learned about callbacks via a tutorial. The instructor mentioned that callbacks are used everywhere in code amongst JavaScript developers. What I understand so far is that these callbacks store a function within a function to be executed at a later time, but wouldn't it be simpler and more efficient to store a value in a variable and create a function that logs your desired output? Can’t the callback alternative (typed below) be executed at a later time as well? 

// Callback Example:
     
function callbackExample(name, callback){
    log(callback(name)); 
}

callbackExample('Adee Otana', function(name){
    return 'Hello ' + name; 
}); 
     
     
// Alternative: 

let name = 'Adee'; 
 
function callbackAlt(name){
    log('Hello ' +  name); 
}
 
callbackAlt(name); 
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