Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

224
Visualizações
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 Respostas
Responde à pergunta

0

Comma operator returns the last element

No tuples in JavaScript

almost 4 years ago · Santiago Trujillo Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda