Daniel Bastos Daniel Bastos - 10 months ago 63
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?


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"