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

183
Views
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 answers
Answer question

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 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!