Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda