Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return statement with multiple comma separated values [duplicate]

Tags:

javascript

Possible Duplicate:
Javascript syntax: what comma means?

What does this pattern return? How does it work?

return myfunc(), myobj.myvar = someobj.prop, myobj

I have not come across this pattern before but have been looking at the Bing Maps Ajax Control and have noticed this pattern several times.

As I understand it multiple values are not returned. So what does this pattern do? What is returned? What is this pattern's benefit?

like image 728
Duncan Gravill Avatar asked Apr 23 '12 16:04

Duncan Gravill


People also ask

How do I return Comma Separated Values in Excel?

If you're working with Excel 2019 or earlier, enter this VLookup return multiple values in one cell (separated by a comma) formula by pressing “Ctrl + Shift + Enter”.

How do you Vlookup a comma separated value in one cell?

Using Asterisk Wildcard Character with Vlookup Search Key It is the widely used method to Vlookup in a comma-separated value column in Google Sheets. It's by using the asterisk (*) wildcard character.

How do I get comma separated values in SQL?

In order to fetch the comma separated (delimited) values from the Stored Procedure, you need to make use of a variable with data type and size same as the Output parameter and pass it as Output parameter using OUTPUT keyword.

What are YouTube Comma Separated Values?

They are the descriptive phrases that a creator uses while uploading their videos from the YouTube Studio to describe its content and help people find them. You can add multiple tags for every YouTube video, separated by commas — the upper limit on tags for YouTube is 500 characters.


1 Answers

It's the comma operator. It evaluates its left-hand operand, throws the result away, evalutes its right-hand operand, and takes that as its result value. It's left-to-right associative, so a, b, c evaluates a, then b, then c, and takes the result of c as its value.

In your example, it's exactly like:

myfunc(); myobj.myvar = someobj.prop; return myobj; 

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. (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.)

Since you've said it's a minifier: The very small 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:

if (someCondition) {     myfunc();     myobj.myvar = someobj.prop;     return myobj; } 

...using the comma operator, the minifier can do this (63 characters):

if(someCondition)return myfunc(),myobj.myvar=someobj.prop,myobj 

...rather than this (65 characters):

if(someCondition){myfunc();myobj.myvar=someobj.prop;return myobj} 

...without changing the functionality of the code, if what follows is a } or some other appropriate character (or end-of-file) to trigger automatic semicolon insertion at the end. Otherwise, it would need the ; on the first one, but that still saves one character.

like image 134
T.J. Crowder Avatar answered Sep 18 '22 17:09

T.J. Crowder