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

134
Views
Different results by using destructuring - Javascript

I understand that these two calls should return the same value. I think the assignment I made is wrong but I don't see how to do it right.

info2 () returns the correct value while info () does not.

Client.prototype.info2 = function () {
    return (this.AccountType())
}
Client.prototype.info = function () {
    const {AccountType} = this
    return (AccountType())
}

------- All code -------

function Client(name, balance) {
    this.name = name;
    this.balance = balance;
}

Client.prototype.AccountType = function () {
    const {balance} = this
    let type;

    if (balance >= 10000) {
        type = 'Platinum'
    } else if (balance >= 5000) {
        type = 'Gold'
    } else {
        type = 'Standard'
    }
    return type;
}

//Expected result: 'Gold'
// Result: 'Gold'

Client.prototype.info = function () {
    const {AccountType} = this
    return (AccountType())
}
//Expected result: 'Gold'
// Result: 'Standard'

Client.prototype.info2 = function () {
    return (this.AccountType())
}
//Expected result: 'Gold'
// Result: 'Gold'

//instances

const Pedro = new Client('Pedro', 8000)
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!