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

211
Views
How is this code rewriting the variable through the loop?

I understand how the loop works here but I'm slightly confused as to how I am able to keep re-writing the data variable and it still returns the entire <tr> body?

I would have expected the last statement </tr> to be the final value of data but somehow it's including everything and returning a complete HTML block.

Noob question, but I can't figure it out. I've never worked with HTML like this.

let data = "";

if (this.tasks.length > 0) {
  for (let i = 0; i < this.tasks.length; i++) {
    data += '<tr>'
    data += '<td>'+(i+1)+". " + this.tasks[i] + '</td>';
    data += '<td><button onclick="app.Edit(' + i + ')"  class="btn btn-warning">Edit</button></td>';
    data += '<td><button onclick="app.Delete(' + i + ')"  class="btn btn-danger">Delete</button></td>';
    data += '</tr>';
  }
}
about 4 years ago · Juan Pablo Isaza
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!