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

195
Vistas
how can i get age from this keyword?
const meDetails = {
    firstName: 'arman',
    lastName: 'soltani',
    birthday: 1991,
    hasDriverLicense: true,

    calcAge: function () {
        this.age = 2037 - this.birthday;
        return this.age;
    }
};

console.log(meDetails.age);

why the age is not defined??

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

the variable of named 'age' is not initialized before calling calcAge.

at first you should call calcAge to init meDetailes.age variable at runtime then meDetails.age is valued and you can use it

about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to call calcAge() first to set the age property

meDetails.calcAge();
console.log(meDetails.age);

But you probably want a getter for age.

const meDetails = {
    firstName: 'arman',
    lastName: 'soltani',
    birthday: 1991,
    hasDriverLicense: true,
    
    get age() {
      return 2037 - this.birthday;
    }
};

console.log(meDetails.age);

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