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

101
Views
javascript: memory difference of resetting a set variable?

Given the code:

function foo() {
  if (!this.isValid) {
    this.isValid = true; 
  }
}

and if I have foo() triggered by an resize event, is it any less efficient to do this:

function foo() {
  this.isValid = true; 
}

where it would be constantly setting this.isValid = true . The end result is the same but it's just resetting the variable over and over. Is there a difference memory wise to either one?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There wont be significant difference in both of them. As in the case of if, you ll have a comparison added. Incase of direct resetting of the value. you ll skip the comparison but the assignment operator will take up some time.
This can help for a cleaner code

function foo() {
   this.isValid = this.isValid || true; 
}
// so you value will not be overwritten
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!