I know eval and with are usually discouraged, but putting that aside for the moment, I’m having trouble getting this code to work:
with({ a: 'hello world' }){
var output = eval('{ text: a }')
}
I was expecting output to be the object:
{ text: "hello world" }
but instead output is the string ‘hello world’
Can someone help me see what I’m missing?
You need parentheses around it:
see e.g. Why does JavaScript's eval need parentheses to eval JSON data?