Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is this python tuple-like syntax in Javascript actually doing?

What is going on in this Javascript code? Is there a name for this or some place to learn more about the specific behavior illustrated?

I didn’t think coding a "tuple" in JS would be valid syntax, but it seems to be. However the resulting variable definitely doesn’t behave as a tuple, which is expected given JS’s lack of support for them.

It’s behavior seems very odd to me though.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It only gets 1 of the two values stored into it, and strangely removing the parenthesis is still valid javascript but ends up storing the opposite value into the varible

-> x = (90, 27);
<- 27
-> x
<- 27

-> x = 90, 27;
<- 27
-> x
<- 90

>Solution :

Comma operator returns the last element

No tuples in JavaScript

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading