Comma separated number/function in parenthesis in JavaScript?

2.1k Views Asked by At

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.

1

There are 1 best solutions below

1
natedavisolds On BEST ANSWER

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.