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

243
Views
Javascript variable setting values, trying to understand meaning

Can someone please explain the below code for me?

  1. Is the line setting multiple variables at the same time? If so, what is are they?
  2. If it is setting multiple variables, I would have expected all the items to be X=Y, but instead I get random variables within the line, like reevVal, mmareev, amareev, fvVal.

Any help is greatly appreciated.

var balance = $(".input-balance"), value = $(".balance-value"), reevVal, mmaVal = $(".mma-val span"), mmareev, amaVal = $(".ama-val span"), amareev, triggerPlus = "false", triggerMinus ="false", fvVal;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

var x = 0, y, z = 1

is equivalent to

var x = 0;
var y; // undefined
var z = 1

There's also the similar, but different, comma operator that lets you "group" up multiple expressions into a single expression. The value of the last sub-expression is returned, but all sub-expressions are evaluated:

let x = (5, doSix(), 7); // x = 7
x = 8, doNine(), 10; // 10

Note the parens are necessary in the 1st line above to make it clear it's a single declaration and not a list of declarations like in the 1st example. The parens aren't necessary in the 2nd line, since there's not let|var|const so it's not a declaration, but an assignment.

In practice, it's most common in for loops where you're constrained to a single expression:

for (let i = 0, j = 10; i < j; i++, j--)
  console.log(i, j);

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!