1

Below there're two pieces of code. I searched a question like this but I haven't found yet. So I don't understand why in my first piece of code my function found my parameter, in this example filterId, but not in the second.

I guess it could be because filterValue is like a var declaration, What is the difference between var and let in Typescript?, instead of a block-scoped, as let. Is it ok this idea?

This is works:


    getServiceAreasFiltered (page: number, filterValue: string): Observable {
      const filterId = filterValue;
      this._http.post(resource, content).pipe(
        flatMap(area => area.results),
        filter((area: ServiceAreaListItem) => area.guid === filterId),
      ).subscribe(x => x);
    }

This is not works:


    getServiceAreasFiltered (page: number, filterValue?: string): Observable {
      this._http.post(resource, content).pipe(
        flatMap(area => area.results),
        filter((area: ServiceAreaListItem) => area.guid === filterValue),
      ).subscribe(x => x);
    }

Paleo
  • 21,831
  • 4
  • 65
  • 76
  • 1
    What error are you getting? – wkrueger May 16 '18 at 21:56
  • I tried to reproduce the error and I don't know why but now the second piece of code works as the first piece. Despite this, my question is still the same: are parameters-passing block-scoped or function-scoped? – Luca Basilico May 17 '18 at 11:47
  • 1
    Block-scoped or function-scoped for the function parameters? It is the same thing. – Paleo May 17 '18 at 15:15

0 Answers0