Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
Why does this JavaScript assignment not raise an error: const a = (1, 2, 3, 4);

const a = (1, 2, 3, 4);
console.log(a);

const b = 1, 2, 3, 4;
console.log(b);

In the above example, a will be assigned the value 4, while the second line will raise an error. Why does the first assignment "succeed". Why is it valid JS syntax?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The comma operator returns the last expression listed. It works in the first case because it is parenthesized and parsed as a single expression. However, once a valid expression is finished after a = - in the second case, 1 - and the next token is a comma, JavaScripts expects another identifier to declare, so you can declare multiple variables like this:

let a = 1, b = 2;
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda