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

229
Vistas
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 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