Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!