Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

75
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!