Comma separated number/function in parenthesis in JavaScript?

dot.js, javascript

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.

Problem

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.

Original source

Related problems