const Declarations in es6 (ES2015)

InstructorJacob Carter

Share this video with your friends

Send Tweet

Read only variables are available in JavaScript (es6/es2015). We will use const declarations and their benefits, like read only and block scope.

Varghese Pallathu
~ 9 years ago

In this redux (https://github.com/reactjs/redux/blob/master/examples/counter/components/Counter.js) example, I see some code:

const { value, onIncrement, onDecrement } = this.props

Your course did not cover something like this. Could you please explain what does the above do?

Jacob Carterinstructor
~ 9 years ago

This syntax is creating four variables. One for each property of the props object and one for the object as a whole. See this babel translation of the code to ES5. http://tinyurl.com/hwpox2p

Xiao Chen Xing
~ 8 years ago

Can you talk about the use and values of const function? Is it also just protecting the function variable being assigned to a different value?

Mike
~ 8 years ago

Nicely explained.

Venkata Janapareddy
~ 8 years ago

Could you please tell me how you are running the js file in the built in terminal? Thanks