Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!ecngs!feeder2.ecngs.de!46.4.82.166.MISMATCH!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Why does (a,b,c) return only c? Supersedes: <2074322.mqz4NpIYxF@PointedEars.de> Date: Tue, 26 May 2015 12:26:19 +0200 Organization: PointedEars Software (PES) Lines: 46 Message-ID: <1687513.QYX3roR0lP@PointedEars.de> References: <55630af5$0$13000$c3e8da3$5496439d@news.astraweb.com> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1432636140 20493 eJwFwYkRwDAMArCV/EEu47jk2H+ESmgmdYbgwPD6bWVuxQrcowBh3QigPlvyNJ0Yvu71Dyi6EXg= (26 May 2015 10:29:00 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Tue, 26 May 2015 10:29:00 +0000 (UTC) User-Agent: KNode/4.14.2 Cancel-Key: sha1:s6GXb/bxrfWOfpRFittlgVbpOk4= X-User-ID: eJwFwYEBwCAIA7CXBEvRc0DW/09YEpvGl2AQoVAK94Qt4xUK85Ex1YbK8dez+0PsdDIfF1tXXC7S3OZ0/UYdFTg= Cancel-Lock: sha1:MtPHDCsivGzpUDk5d0QvI/Mah4k= X-NNTP-Posting-Host: eJwFwQEBwDAIAzBLbGvh2IGCfwlP+Px4B5wOLtf37rzwSeRMW9dNOxRUSMxrKbQso7bsqx8scxH7 Xref: csiph.com comp.lang.javascript:27880 Joao Rodrigues wrote: > 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: > Bogus. | //original | var a = 7, 5; | //apply = operator | var a, 5; //a is now 7 | //SyntaxError: missing variable name is not a syntax error because “we [haven’t] wrapped the variable assignment in parentheses”, but because _“5” is not a valid variable name_. And the value of “a” is not 7, but _not defined_ at this line (that is different from the “undefined” value), because var a = 7, 5; is a syntax error already: | >>> var a = 7, 5; | Uncaught SyntaxError: Unexpected number | at Object.InjectedScript._evaluateOn (:895:140) | at Object.InjectedScript._evaluateAndWrap (:828:34) | at Object.InjectedScript.evaluate (:694:21) The subsequent example in that article, where it works, is | //original | var a = (7, 5); | //apply group | var a = 5; where not only the parentheses have been inserted, but magically the comma has been replaced by a “=”. Surprise. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.