In this introductory course of Redux https://egghead.io/lessons/javascript-redux-store-methods-getstate-dispatch-and-subscribe?series=getting-started-with-redux, the presenter says that the following two lines are identical
const { createStore } = Redux;
var createStore = Redux.createStore;
I've just searched for ES6 const
documentation, and it does not quite answer my question, how are these two lines identical?
This is not related to
const
(which is just a way to define a constant), but instead to object destructuring.So these are all identical:
In the line
const { createStore: createStore } = Redux;
, the firstcreateStore
defines the property ofRedux
to get. The secondcreateStore
defines the name under which is available after the declaration.In addition, in ES6 defining objects like
{ name: name }
can be shortened to{ name }
.