Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
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.

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
almost 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Comma operator returns the last element

No tuples in JavaScript

almost 4 years ago · Santiago Trujillo Report

0

It is just javascript evaluating expression, when you have parenthesis () javascript will evaluate the whole expression inside the parenthesis first and then assign it to the variable since x = (1,2) 2 is the last evaluated value will be assigned to x. But if you don't have parenthesis then it evaluates step by step expression x = 1,2 the first expression it finds is x=1 and then just evaluates 2 it's as if you typed x=1; 2;

almost 4 years ago · Santiago Trujillo Report

0

That's not a tuple. JavaScript does not have tuples. You're simply doing

x = 90, 27

but wrapping the expression 90, 27 in parentheses. The reason why it's returning 27 is because that's the last element.

almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!