Why doesn't this eval
call alert("Summer")
?
eval('(caption="Summer";alert(caption))');
Does it have something to do with the quotes in "Summer"?
Why doesn't this eval
call alert("Summer")
?
eval('(caption="Summer";alert(caption))');
Does it have something to do with the quotes in "Summer"?
Share Improve this question edited Sep 22, 2011 at 13:40 Richard JP Le Guen 28.8k8 gold badges93 silver badges120 bronze badges asked Feb 14, 2010 at 23:33 JamesBrownIsDeadJamesBrownIsDead 1152 silver badges4 bronze badges 2 |4 Answers
Reset to default 13Uncaught SyntaxError: Unexpected token ;
The outer parentheses make no syntactical sense. Try this:
eval('caption="Summer";alert(caption)');
Chrome console:
eval('(caption="Summer";alert(caption))')
SyntaxError: Unexpected token ;
This works:
eval('caption="Summer"; alert(caption)')
The extra parentheses are wrong, this is correct:
eval('caption="Summer";alert(caption)');
A more better way to do this and avoid syntax problem is to do following,
eval(function(){var x="test"; alert(x)}());
,
operator:eval('(caption="Summer",alert(caption))');
– Dominic Cooney Commented Feb 15, 2010 at 0:50