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:
var createStore = Redux.createStore;
const { createStore: createStore } = Redux;
const { createStore } = Redux;
In the line const { createStore: createStore } = Redux;
, the first createStore
defines the property of Redux
to get. The second createStore
defines the name under which is available after the declaration.
In addition, in ES6 defining objects like { name: name }
can be shortened to { name }
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With