Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #27876

Re: Why does (a,b,c) return only c?

From "D. Aaron Sawyer" <aaron@110.net>
Newsgroups comp.lang.javascript
Subject Re: Why does (a,b,c) return only c?
Date 2015-05-25 19:49 -0300
Organization Hardly any
Message-ID <mk08s9$nga$1@dont-email.me> (permalink)
References (1 earlier) <XnsA4A5916ACD1C1eejj99@194.109.133.246> <mjv68c$tft$1@solani.org> <XnsA4A599E5B8C9Eeejj99@194.109.133.246> <55636189$0$2901$e4fe514c@news.xs4all.nl> <comma-operator-20150525200013@ram.dialup.fu-berlin.de>

Show all headers | View raw


On 2015.05.25 15:01, Stefan Ram wrote:
> Luuk <luuk@invalid.lan> writes:
>> Why use comma operators?
>
>    I have my preferred formatting style, which looks like:
>
> return
> { a: 22,
>    b:  7 };
>
>    But JavaScript will not let me use it. I have to use the
>    comma operator!
Automatic Semicolon Insertion (ASI) will terminate the return statement as follows:

   return;
   { a: 22,
     b:  7 };

(see, for example, http://www.ecma-international.org/ecma-262/5.1/#sec-7.9 )

The anonymous object with properties a and b is unreachable at execution time.

I am not sure which error is the one you experienced.  If you wish to return
an (anonymous) object, then use

   return { a: 22,
            b:  7 };
or
   return { a: 22
          , b:  7
          };

>
> return 0,
> { a: 22,
>    b:  7 };
>
>>>>>> Why does (a,b,c) return only c?
>
>    Expressions do not /return/ values, expressions /have/ values.
>    (More precisely: The /evaluation/ of an expression yields a value.)
>    /Functions/ return values.
>

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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