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

187
Vistas
Which of the two codes is the better way to store variables?

I'm making a calculator in javascript and I'm wondering which code is better for storing variables.

The following is some code of a function that operates when an operator is clicked.

In this case, oldNum is the first value before the operator, and newNum is the second value after the operator.

code 1:

result ? (oldNum = result) : newNum ? (oldNum = newNum) : (oldNum = oldNum);

code 2 :

result ? (oldNum = result) : !newNum || (oldNum = newNum);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Both codes are syntactically valid.

I would prefer code with fewer conditions if possible for readability and to avoid confusion. If both codes yield the same results, then having more conditions is not necessary unless you have an objective and use for them.

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