Daniel Bastos Daniel Bastos - 1 year ago 100
Javascript Question

const keyword usage in Javascript

I was reading the source for a MeteorJS package (this one) when I came across this:

const {
pure = true,
} = expandedOptions;

I did some research to figure out what this code would do, but couldn't find any other instance of const being used like this, or any documentation to clarify it for me.

Any hints, please?

Answer Source

It is using es6 to unpack (or destructure) the values inside the expandedOptions object.

const val = {a:1, b:"hello"};
const {
} = val;

console.log(a); //1
console.log(b); //"hello"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download