Ruffeng Ruffeng - 1 year ago 67
Javascript Question

Use of hashes to declare a variable in ReactJS/Javascript Es6

I would like to know the difference between:

const data = this.props.content;


const {data} = this.props.content;

I saw it before but declaring 3 or 4 variables all together. However I've never seen it with just 1 variable.

What's the difference?

Answer Source

When writing with just one variable you get the syntactic advantage of using the same name for your variable. I believe the example you listed should be altered slightly which illustrates and hopefully answers your question.

const data = this.props.content; // is exactly the same as
const {content} = this.props;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download