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

205
Views
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 answers
Answer question

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 Report

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 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!