What is this es6 syntax called?

Viewed 76

I am relatively new to es6. I came across the following syntax and can't figure out what is it called.

let parameter = 'key1'; 
const obj = {
    'key1': 'value1',
    'key2': 'value2',
    'key3': 'value3',
  }[parameter];
2 Answers

That concept is not specific to ES6.

That's just an object, out of which you're getting 1 value, depending on the parameter.

It is similar to:

let parameter = 'key1'; 
const temp = {
    'key1': 'value1',
    'key2': 'value2',
    'key3': 'value3',
}
const obj = temp[parameter];

Except temp is never declared.

Statement 1: variable declaration and definition.

Statement 2: variable declaration, inline object definition and accessing it using an indexer.

FYI: your code is plain old JavaScript. Only the const and let keywords are ECMAScript 6.

Related