Reputation: 1354
Why next code is valid Javascript code?
var global = (1,eval)('this');
alert(global);
Upvotes: 6
Views: 166
Reputation: 263047
That's because the comma operator returns its second operand (and evaluates both).
The code in your question is equivalent to:
1;
var global = eval('this');
alert(global);
Upvotes: 10