Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
I don't know why this 'this' method doesn't work?
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 Respuestas
Responde la pregunta

0

You are storing a function, not calling it that's why it should print you undefined. To fix it you should call it with list.calcAge().

Your code works and this.age = 2002 - this.birthYear creates the property you want, you just need to call it before using it.

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 Denunciar

0

Call your function. list.calcAge() You can print it like this console.log(list.calcAge()) You were close though!!

about 4 years ago · Juan Pablo Isaza Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda