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

77
Visualizações
parentheses upon creation a object

why are we putting parentheses upon creating an object, for example, what is gonna happen if we removed the parentheses around the (new String())?

var upper = (new String(str)).toUpperCase(); 
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There's no point to those parentheses, new has high precedence and the result would be exactly the same if you didn't have the parentheses there.


Your question applies generally (for instance, (new Date()).toISOString() vs. new Date().toISOString()), but just for what it's worth new String(x) in JavaScript is generally unnecessary at best or potentially a bug at worst. It creates a string object, whereas normally we interact with string primitives. The difference can matter sometimes, for example new String("x") == new String("x") is false, because two separate objects are never == to each other.

There's almost never any reason to use a string object.

That code may have been trying to defend against the possibility that str wasn't a string, by converting it to one. If so, remove the new:

var upper = String(str).toUpperCase();

String without new does a type conversion (to a string primitive).

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