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

185
Views
No sé por qué este método 'este' no funciona.
const list = { name: 'Harry Potter', birthYear: 1995, calcAge: function () { this.age = 2002 - this.birthYear; return this.age; } }; console.log(list.age);
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Está almacenando una función, no llamándola, por eso debería imprimirlo undefined . Para solucionarlo, debe llamarlo con list.calcAge() .

Su código funciona y this.age = 2002 - this.birthYear crea la propiedad que desea, solo necesita llamarla antes de usarla.

 const list = { name: 'Harry Potter', birthYear: 1995, calcAge: function () { this.age = 2002 - this.birthYear; return this.age; } }; list.calcAge() console.log(list.age);
about 4 years ago · Juan Pablo Isaza Report

0

Llame a su función. list.calcAge() Puedes imprimirlo así console.log(list.calcAge()) ¡Aunque estuviste cerca!

about 4 years ago · Juan Pablo Isaza Report

0

 const list = { name: 'Harry Potter', birthYear: 1995, calcAge() { this.age = 2002 - this.birthYear; return this.age; }, }; console.log(list.calcAge());

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!