0

Consider the following code

let foo = 'test'
const obj = {foo}

If we console.log(foo) we can see that obj is an object {foo : 'test'}

How does that work?

I mean, I would expect const obj={foo} to be evaluated into const obj = {'test'} which will throw a syntax error.

So why variable foo inside curly braces in the right part of an assignment becomes foo: "valueof" foo instead of being just the value of foo?

Marios
  • 339
  • 1
  • 14

0 Answers0