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

What exactly the above JavaScript object represents

t.niese
  • 39,256
  • 9
  • 74
  • 101
saketh
  • 803
  • 1
  • 10
  • 24
  • 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
  • 32,342
  • 7
  • 71
  • 76