0

These 2 code blocks function exactly the same in a snippet from an Angular 2 service. If there is only one statement in the function body of the "then", is it safe to say that a "return" statement is unnecessary and that these blocks of code are identical in operation?

getTodos(): Promise<Todo[]> {
    return this.http.get(this.todosUrl)
    .toPromise()
    .then(response => response.json() as Todo[])

This code block has a "return" statement in the "then"

getTodos(): Promise<Todo[]> {
    return this.http.get(this.todosUrl)
    .toPromise()
    .then(response => { return response.json() as Todo[]})
eko
  • 34,608
  • 9
  • 60
  • 85
gim
  • 31
  • 4
  • This has nothing to do with promises. – Bergi Jan 09 '17 at 22:01
  • See also [Syntax of arrow functions, to use or not to use {} around the body](http://stackoverflow.com/q/40636513/1048572) – Bergi Jan 09 '17 at 22:03
  • I see this... "(param1, param2, …, paramN) => expression" is equivalent to: "(param1, param2, …, paramN) => { return expression; }" from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions – gim Jan 09 '17 at 23:20

0 Answers0