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

213
Views
Basic variable declaration and memory in Javascript/Vue

I have a very basic question about declaring variable in Javascript/Vue.

function myFunction () {
  let myVars = this.myVars;
  forEach(myVars, (var) => {
    // Do something with var
  } 
}

VS

function myFunction () {
  forEach(this.myVars, (var) => {
    // Do something with var
  } 
}

I was wondering if the first style of coding would waste so much resources to the point that it affect performance in modern computer/browser?

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

0

There's no impact on performance here. When the myFunction is called, myVars is registered in the function scope. Then you make myVars refer to this.myVars, if the value in this.myVars is an array or object, then there is no deep copy operation here. Both are referring to the same object. Finally, when the function execution completes, the scope created is destroyed so no memory leaks there.

One suggestion though is to prefer const over let over var.

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!