Syntax of fat arrow functions (=>), to use or not to use {} around the body

后端 未结 5 1044
梦谈多话
梦谈多话 2020-12-07 04:40

I am looking at this code - https://facebook.github.io/react-native/docs/network.html

return fetch(\'https://facebook.github.io/react-native/movies.json\')
          


        
5条回答
  •  伪装坚强ぢ
    2020-12-07 05:20

    If you don't wrap the body of an arrow function with curly brackets, it will evaluate the expression and return the result implicitly. If you wrap it with curly brackets, the result is not implicitly returned and you have to do it explicitly.

    For this reason, the second part 'equals' the following:

    .then(function(responseJson) {
        return responseJson.movies;
    })
    

提交回复
热议问题