title: angular 4 function return boolean = undefined
body: <p>I can't seem to figure this out. I have a DataService (a.k.a. ds) and a component. The component calls a function doesUserExist():</p>
  
  <pre><code>console.log("boolean="+this.ds.doesUserExist());
  </code></pre>
  
  <p>This always comes up as undefined. Here's the function in DataService:</p>
  
  <pre><code> doesUserExist(){
      var bool:boolean;
      var myvars = this.af.list('/accounts/'+this.uid) as FirebaseListObservable&lt;Listing[]&gt;;
  
      myvars.subscribe(data=&gt;{
            console.log("length="+data.length)
            if (data.length===0){
              bool = false;        
            }       
          })
          return bool;
  
        }
  </code></pre>
  
  <p>I tried putting the <code>var bool:boolean</code> as a public variable too, but no matter what happens, this comes as undefined. </p>
  
  <p>I also set <code>var bool:boolean=true</code> and bool WILL equal false in the if statement above (I've checked via console.log) and instead of coming back as <code>false</code> it's still <code>true</code> per the designation above.</p>
  
  <p>So what am I doing wrong with this? I've searched around and I tried:</p>
  
  <p><code>Boolean([return bool])</code> but Code doesn't like that</p>
  
  <p>I tried putting the <code>returns</code> in the if statement as well. That doesn't work.</p>
  
  <p>Thank you!</p>