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

220
Visualizações
I cannot return the value of the function, but I can console.log it

I am trying to write a website with chat, file storage etc. I am using JS and Google Firebase. The problem is that I'd like to check if the user already exists, I wrote a function to check this, but it seems not to work. I can console.log the value (and this works fine) but I cannot return the value (every time it shows that the variable is undefined).

Here is my code:

function checkIfTheUserExists(user)
{
    db.ref("messages/" + user).once("value").then(function(snapshot) {
        const ifPathExists = snapshot.exists();
        console.log(ifPathExists);
    });
}

When I am trying to return the value of ifPathExists it always shows undefined, even when I am trying to assign the value to another variable.

Please use straightforward explanation that I can easily understand.

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