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

135
Visualizações
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
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