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

258
Visualizações
Difference between this.variable and this._variable in JavaScript?

I'm learning the Codecademy Advanced JavaScript course, I'm learning about classes.

In their code, I feel this.variable and this._variable have no different but they require to write this.variable even though 2 options return the same output.

Can you please explain the differences if you understand this?

These are some examples of code

class Dog {
  constructor(name) {
    this._name = name
  }
}

Is it different from:

class Dog {
  constructor(name) {
    this.name = name
  }
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

**

1.Names can contain letters, digits, underscores, and dollar signs. 2.Names must begin with a letter Names can also begin with $ and _ 3.Names are case sensitive(y and Y are different variables)

**

about 4 years ago · Juan Pablo Isaza Relatório

0

Define variables preceded by an underscore is just a convention to mark them as private, but javascript doesn't support encapsulation so this is only for helping the developer identify private variables.

In this post you have a similar question: Is the underscore prefix for property and method names merely a convention?

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