-5
  const sample=  {
                   [name]:value
                 }

What exactly the above JavaScript object represents

t.niese
  • 36,631
  • 8
  • 65
  • 95
saketh
  • 773
  • 1
  • 8
  • 21
  • it means to use the variable `name` and the value it holds as the key, not `"name"` as the key. – Nick Parsons Feb 20 '19 at 06:59
  • This is not JSON, but a JavaScript Object. JSON is a string based representation of data. And the square braces would not be a valid syntax in JSON. – t.niese Feb 20 '19 at 07:00

1 Answers1

0

This means name is variable

like

let name = 'John';

 const sample=  {
                   [name]:value
                 }

So sample will be like this

sample.John = value

Try this

let name = 'John';

 const sample=  {
                   [name]:"I am John"
                 }
                 
console.log(sample);              
kiranvj
  • 27,729
  • 5
  • 65
  • 72