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


Groups > comp.lang.javascript > #35943 > unrolled thread

comma operator?

Started byLuca <luca@please.nospam.it>
First post2019-01-01 18:15 -0500
Last post2019-01-02 08:17 -0500
Articles 6 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  comma operator? Luca <luca@please.nospam.it> - 2019-01-01 18:15 -0500
    Re: comma operator? Luca <luca@please.nospam.it> - 2019-01-01 18:24 -0500
      Re: comma operator? rbowman <bowman@montana.com> - 2019-01-01 17:09 -0700
        Re: comma operator? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-01-02 09:34 +0100
    Re: comma operator? Abhinav Sharma <a.sharma.nitk@gmail.com> - 2019-01-02 00:32 -0800
      Re: comma operator? Luca <luca@please.nospam.it> - 2019-01-02 08:17 -0500

#35943 — comma operator?

FromLuca <luca@please.nospam.it>
Date2019-01-01 18:15 -0500
Subjectcomma operator?
Message-ID<q0gsa4$iad$1@gioia.aioe.org>
Not sure how to google for this. What's the use of the comma operator 
used like this in JS?

  let matrix = [], row;

I am studying this React.js example and the construct above is puzzling me.

https://github.com/danielr18/memory-grid-game/blob/master/lib/Game.js#L18

thanks

[toc] | [next] | [standalone]


#35944

FromLuca <luca@please.nospam.it>
Date2019-01-01 18:24 -0500
Message-ID<q0gsrh$jua$1@gioia.aioe.org>
In reply to#35943
I think I get it now. It's a simple use of "let" to declare two 
variables to be used within the module. The first variable is also 
initialized as an empty list.

Sorry for the confusion

On 1/1/2019 6:15 PM, I wrote:
> 
> Not sure how to google for this. What's the use of the comma operator 
> used like this in JS?
> 
>   let matrix = [], row;
> 
> I am studying this React.js example and the construct above is puzzling me.
> 
> https://github.com/danielr18/memory-grid-game/blob/master/lib/Game.js#L18
> 
> thanks
> 
> 

[toc] | [prev] | [next] | [standalone]


#35945

Fromrbowman <bowman@montana.com>
Date2019-01-01 17:09 -0700
Message-ID<g92dmlF1ht4U1@mid.individual.net>
In reply to#35944
On 01/01/2019 04:24 PM, Luca wrote:
> I think I get it now. It's a simple use of "let" to declare two
> variables to be used within the module. The first variable is also
> initialized as an empty list.
>
> Sorry for the confusion

Comma separated lists of variables have been around since FORTRAN if not 
before. It saved work when you were using punch cards but it can be 
confusing and lead to errors.

let a, b, c, d = 3;

may or may not do what the programmer intended. I've always preferred 
explicit, one variable per line, declarations but that's just me.

[toc] | [prev] | [next] | [standalone]


#35947

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2019-01-02 09:34 +0100
Message-ID<XnsA9CB615784DE0eejj99@194.109.6.166>
In reply to#35945
rbowman <bowman@montana.com> wrote on 02 Jan 2019 in comp.lang.javascript:

> On 01/01/2019 04:24 PM, Luca wrote:
>> I think I get it now. It's a simple use of "let" to declare two
>> variables to be used within the module. The first variable is also
>> initialized as an empty list.
>>
>> Sorry for the confusion
> 
> Comma separated lists of variables have been around since FORTRAN if not 
> before. It saved work when you were using punch cards but it can be 
> confusing and lead to errors.
> 
> let a, b, c, d = 3;
> 
> may or may not do what the programmer intended. I've always preferred 
> explicit, one variable per line, declarations but that's just me.

What about:?

const a,b,c,d;

It seems to be the ideal form of content exclusion.



Spoiler:

Uncaught SyntaxError: Missing initializer in const declaration



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#35946

FromAbhinav Sharma <a.sharma.nitk@gmail.com>
Date2019-01-02 00:32 -0800
Message-ID<eaaa8ad7-5a86-489e-b606-74e1fa8f7221@googlegroups.com>
In reply to#35943
On Wednesday, January 2, 2019 at 4:45:23 AM UTC+5:30, Luca wrote:
> Not sure how to google for this. What's the use of the comma operator 
> used like this in JS?
> 
>   let matrix = [], row;
> 
> I am studying this React.js example and the construct above is puzzling me.
> 
> https://github.com/danielr18/memory-grid-game/blob/master/lib/Game.js#L18
> 
> thanks

You can declare multiple variables separated by comma on a single line.
Although not a preferred way to do so as per common style guides for javacript.

[toc] | [prev] | [next] | [standalone]


#35948

FromLuca <luca@please.nospam.it>
Date2019-01-02 08:17 -0500
Message-ID<q0idkl$1195$1@gioia.aioe.org>
In reply to#35946
On 1/2/2019 3:32 AM, Abhinav Sharma wrote:
> On Wednesday, January 2, 2019 at 4:45:23 AM UTC+5:30, Luca wrote:
>> Not sure how to google for this. What's the use of the comma operator
>> used like this in JS?
>>
>>    let matrix = [], row;
>>
>> I am studying this React.js example and the construct above is puzzling me.
>>
>> https://github.com/danielr18/memory-grid-game/blob/master/lib/Game.js#L18
>>
>> thanks
> 
> You can declare multiple variables separated by comma on a single line.
> Although not a preferred way to do so as per common style guides for javacript.
> 

yeah, I get it now. What was confusing me was probably a Python 
interference. I was interpreting this as some kind of:

   let matrix = ([], row);

:)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web