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

164
Visualizações
Should properties of constants be capitalized?

I know that it is conventional to capitalize constant values in programming, but would you do the same for their keys? I am trying to make a string based enum in javascript:

const SEASONS = {
  spring: 'spring',
  summer: 'summer',
  fall: 'fall',
  winter: 'winter'
}

// or

const SEASONS = {
  SPRING: 'spring',
  SUMMER: 'summer',
  FALL: 'fall',
  WINTER: 'winter'
}

Is it conventional to capitalize the keys, if they are also constant? So that you access their values by SEASONS.SPRING instead of SEASONS.spring?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As per MDN, Constants can be declared with uppercase or lowercase, but a common convention is to use all-uppercase letters.

There is no specific rule that the declaration SHOULD be in uppercase.

Uppercase indicates that the variable is a constant and they are immutable.

But the properties inside a constant are mutable and hence they CAN be declared as lowercase.

const SEASONS = {
  spring: 'spring',
  summer: 'summer',
  fall: 'fall',
  winter: 'winter'
}

SEASONS are immutable but SEASONS.spring is mutable, hence that CAN be considered as lowercase.

And again, there is no predefined rule for this. Its upto you, but you should follow the same pattern throughout the application.

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