J
jman
var x = eval("{ 'flag' : 1 }");
alert(x);
alert(x.flag);
why doesn't the above work?
alert(x);
alert(x.flag);
why doesn't the above work?
var x = eval("{ 'flag' : 1 }");
alert(x);
alert(x.flag);
why doesn't the above work?
Because the - eval - method treats its string input as a javascript
program and a javascript program commencing with an opening brace is a
program that starts with a block statement. That makes the content of
the block statement a syntax error.
If you want to have your string interpreted as an object literal you
have to force it into a context were it must be interpreted as an
expression. Putting parenthesis around it will achieve that end.
can you give the code ?
I didn't understand where to put these parenthesis
On Mar 6, 1:07 pm, SAM wrote:
var x = eval("({ 'flag' : 1 })");
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.