How object literals are different from json object?

  Kiến thức lập trình

I was defining a computed property in json object but json treats that property as a string but it works totally fine in object literal, so this makes me curios to know more about of it.

personType = 'student'

const json = '{
'name' : 'jane',
'age' : 20,
'[personType === 'student' ? 'studingAt' : 'workingAt']' : personType === 'student' ? 'oxford university' : 'Audi',
}'

here i am unable to assign computed value for key , which was fine in normal object literals.

LEAVE A COMMENT