Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27875
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Why does (a,b,c) return only c? |
| Date | Mon, 25 May 2015 19:24:18 -0300 |
| Organization | Aioe.org NNTP Server |
| Lines | 34 |
| Message-ID | <mk07ei$t55$1@speranza.aioe.org> (permalink) |
| References | <55630af5$0$13000$c3e8da3$5496439d@news.astraweb.com> <gf4c3c-iks.ln1@mail.binaryfoundry.ca> <XnsA4A5DF4D39BAAeejj99@194.109.133.246> |
| NNTP-Posting-Host | ESUn5VM5DREJ2rZRjvkCnA.user.speranza.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252 |
| Content-Transfer-Encoding | 8bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.javascript:27875 |
Show key headers only | View raw
On 25/05/2015 16:57, Evertjan. wrote: > for (var i = 0, j = 9; i <= 9; i++, j--) > document.write( i + " - " + j + "<br>"); > > "Note that the comma in the var statement is not the comma operator, because > it doesn't exist within an expression. Rather, it is a special character in > var statements to combine multiple of them into one." Commas may be either separators such as in variable statements (ES5.1, §12.2), or operators (ES5.1, §11.14). > > After reading that 3 times, I could sort of understand why this is not > allowed: > > for (var i = 0, var j = 9; i <= 9; i++, j--) The for statement (ES5.1, §12.6.3) has three _optional_ parts: for ( var VariableDeclarationListNoIn ; Expressionopt ; Expressionopt ) In the first part, we can declare variables separated by commas. In the last two parts (expressions), we can use comma operators if we wish, but I think the code becomes cryptic in doing so. But why on Earth would someone use comma operators? Because they let you specify more than one expression where JavaScript expects only one. See examples at: <https://javascriptweblog.wordpress.com/2011/04/04/the-javascript-comma-operator/> -- Joao Rodrigues
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why does (a,b,c) return only c? Steven D'Aprano <steve@pearwood.info> - 2015-05-25 21:43 +1000
Re: Why does (a,b,c) return only c? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-25 14:17 +0200
Re: Why does (a,b,c) return only c? Luuk <luuk@invalid.lan> - 2015-05-25 14:42 +0200
Re: Why does (a,b,c) return only c? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-25 14:58 +0200
Re: Why does (a,b,c) return only c? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-25 14:57 +0200
Re: Why does (a,b,c) return only c? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-25 15:07 +0200
Re: Why does (a,b,c) return only c? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-25 15:32 +0200
Re: Why does (a,b,c) return only c? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-25 17:50 +0200
Re: Why does (a,b,c) return only c? Luuk <luuk@invalid.lan> - 2015-05-25 19:53 +0200
Re: Why does (a,b,c) return only c? "D. Aaron Sawyer" <aaron@110.net> - 2015-05-25 19:49 -0300
Re: Why does (a,b,c) return only c? John-Paul Stewart <jpstewart@sympatico.ca> - 2015-05-25 13:58 -0400
Re: Why does (a,b,c) return only c? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-25 21:57 +0200
Re: Why does (a,b,c) return only c? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-05-25 19:24 -0300
Re: Why does (a,b,c) return only c? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-26 12:26 +0200
Re: Why does (a,b,c) return only c? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-05-26 09:36 -0300
Re: Why does (a,b,c) return only c? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-26 14:42 +0200
Re: Why does (a,b,c) return only c? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-05-26 09:53 -0300
Re: Why does (a,b,c) return only c? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-26 15:15 +0200
Re: Why does (a,b,c) return only c? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-26 15:17 +0200
Re: Why does (a,b,c) return only c? Scott Sauyet <scott.sauyet@gmail.com> - 2015-05-26 08:59 -0700
csiph-web