const Declarations in es6 (ES2015)

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
Varghese Pallathu
~ 8 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 Carter
Jacob Carter(instructor)
~ 8 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
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
Mike
~ 7 years ago

Nicely explained.

Venkata Janapareddy
Venkata Janapareddy
~ 7 years ago

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