Question

I read a line from doT.js:

var global = (function(){ return this || (0||eval)('this'); }());

After it was minified:

l=function(){return this||(0,eval)("this")}();

So what is the (0,eval), I mean what does the comma do?

I played in Chrome's console, (0,1), (2,1), (2,{}), 2,1, etc, it always returns the last one.

Was it helpful?

Solution

The comma operator evaluates both and always returns the last. Much like you said.

You can read up on the comma operator: http://javascriptweblog.wordpress.com/2011/04/04/the-javascript-comma-operator/

Even though I have no idea the purpose of (0||eval)... (0,eval) is the equivalent and one less character.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top