Beginner's: defining const in Redux is confusing

In this Redux introductory course https://egghead.io/lessons/javascript-redux-store-methods-getstate-dispatch-and-subscribe?series=getting-started-with-redux , the facilitator says the following two lines are identical

const { createStore } = Redux; var createStore = Redux.createStore; 

I just searched the ES6 const documentation and this will not quite answer my question, how are these two lines identical?

+6
source share
1 answer

This is not related to const (this is just a way to define a constant), but instead to destruct objects .

So, they are all identical:

 var createStore = Redux.createStore; const { createStore: createStore } = Redux; const { createStore } = Redux; 

On the line const { createStore: createStore } = Redux; the first createStore defines the Redux property to receive. The second createStore defines the name under which it is available after the declaration.

In addition, in ES6, the definition of objects of type { name: name } can be shortened to { name } .

+9
source

All Articles