Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

76
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda