Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's the <a href="http://es5.github.com/#x11.14">comma operator</a>. It runs a series of expressions, in order, and then returns the result of the <em>last</em> of them. Exactly like:</p> <pre><code>myfunc(); myobj.myvar = someobj.prop; return myobj; </code></pre> <p><s>Some people really prefer to do things on one line, even when there's no objective reason to. There no benefit in the example you gave, and in fact it's confusing because it makes it look like the first two bits relate to the value that will ultimately be returned, which they don't.</s> <em>(I wrote that before you told us it was minified code; obviously, being unclear to humans is only an issue in source code, not minified code.)</em></p> <p>Since you've said it's a minifier: The <strong>very small</strong> possible benefit the minifier might have gotten there is if this is part of a conditional block: It can save one or two characters. If we assume the long form looked like this:</p> <pre><code>if (someCondition) { myfunc(); myobj.myvar = someobj.prop; return myobj; } </code></pre> <p>...using the comma operator, the minifier can do this (63 characters):</p> <pre><code>if(someCondition)return myfunc(),myobj.myvar=someobj.prop,myobj </code></pre> <p>...rather than this (65 characters):</p> <pre><code>if(someCondition){myfunc();myobj.myvar=someobj.prop;return myobj} </code></pre> <p>...without changing the functionality of the code, <strong>if</strong> what follows is a <code>}</code> or some other appropriate character (or end-of-file) to trigger <a href="http://es5.github.com/#x7.9">automatic semicolon insertion</a> at the end. Otherwise, it would need the <code>;</code> on the first one, but that still saves one character.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload