title: Trying to access a variable outside constructor scope in Angular 5
body: <p>This is part of my service layer in an Angular project. Why does <code>console.log</code> give me undefined for <code>count</code>? I can only access the value in a subscriber function. I want use the count in BehaviorSubject; how can I access it there?</p>
  
  <pre><code>export class DataService {
  
      public count;
      private baskets;
  
      constructor(private _store: StoreService) {
              this._store.reviewBasketProduct().subscribe(data =&gt; {
              this.baskets = data;
              //console.log(data.len)
              this.count =  this.baskets.length;
          })
  
          console.log('aa' + this.count)
      }
  
      private messageSource = new BehaviorSubject&lt;number&gt;(this.count);
      currentMessage = this.messageSource.asObservable();
  }
  </code></pre>