static async getMovies({
// here's where the default parameters are set for the getMovies method
filters = null,
page = 0,
moviesPerPage = 20,
} = {}) {
let queryParams = {}
.
.
.
}
My guess is that getMovies() has 1 optional parameter. Which is an object with 3 fields. Each field having a different value. So calling getMovies() without any parameter would me get me the first 20 unfiltered movies of page 0. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters
Thanks for the reply. But why an empty object is assigned to the default parameter?
If not you could not call getMovies() like this, without any parameter. With the given signature you can call getMovies in the following ways:
-
getMovies()
which is equivalent togetMovies({})
which is equivalent togetMovies( { filters : null, page : 0, moviesPerPage : 20 } )
-
getMovies( { page : 2 } )
which is equivalent togetMovies( { filters : null, page : 2, moviesPerPage : 20 } )
-
getMovies( { moviesPerPage : 16 } )
which is equivalent togetMovies( { filters : null, page : 0, moviesPerPage : 16 } )
-
getMovies( { page : 2 , moviesPerPage : 16 } )
which is equivalent togetMovies( { filters : null, page : 2, moviesPerPage : 16 } )
- and many more
I am sure you get the pattern. This is standard default parameters usage.
Thanks, @steevej for the explanation. So if I am getting this right, it means to call getMovies() method without or any number of arguments we are assigning an empty object in the parameter signature.
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.