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

337
Views
Using arrow function inside a JavaScript Object?

I'm trying to build muscle memory by using arrow functions, but I seem to be having a conflict with using one inside of an object. Here's my code:

const gwen = {
    firstName : 'Gwen',
    lastName : 'Stacy',
    mass : 78,
    height : 1.69,

    calcBMI: function () {
        return this.mass / (this.height ** 2)
    }

}

const patrick = {
    firstName : 'Patrick',
    lastName : 'Arnolds',
    mass : 92,
    height : 1.95,

    calcBMI: () => this.mass / (this.height ** 2)

}

console.log(gwen.mass, gwen.height, gwen.calcBMI())
console.log(patrick.mass, patrick.height, patrick.calcBMI())

Output from the first object called 'gwen' uses a regular function definition:

78 1.69 27.309968138370508

Output from the second object called 'patrick' is my attempt at using an arrow function inside of an object:

92 1.95 NaN

I've looked up articles on other websites from a search, but it seems nothing has been written based on my specific issue. I'm following along with tutorials and experimentation on the side. Maybe I'm attempting to use an arrow function in the wrong context.

about 4 years ago · Juan Pablo Isaza
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!