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

276
Views
Why is BigInt not a constructor function, unlike Number, Boolean and String?

Number, Boolean and String are constructor functions that correspond to those primitive types.

BigInt is a function that corresponds to the BigInt primitive type, but it is not a constructor function.

new BigInt(1n) // Uncaught TypeError: BigInt is not a constructor

Why?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The functions for new primitive types (Symbol, BigInt) don't get construction signatures because TC39 doesn't think they need them. On this issue on the BigInt proposal, Jordan Harband (TC39 member and former editor of the specification) said:

Just like Symbol, it doesn't make sense to use new with things that produce a primitive. Since BigInt (like Symbol) is a primitive, it should only be invoked as a function.

Pre-ES6 primitive constructors unfortunately must retain their new-ability, for back compat.

and from this one (also Jordan):

...users should never use new with a Number object tho, because it's widely considered a very bad practice to ever use boxed primitives.

The new paradigm (no pun intended) is the one Symbol follows - if you want an object, you have to explicitly pass the primitive into Object. new Primitive() is a footgun, and new primitives should not continue this legacy pattern.

The use cases for new String, etc., are very few and far between (if there even are any that aren't better solved in other ways). Having construction signatures for Number and String and Boolean is confusing (do you create a string just by using a literal, or by using new String? why is it new String("x") === "x" is false? etc.). It looks like the committee decided to avoid that kind of confusion with newer primitives. (They still have object counterparts, it's just slightly less obvious how you get them, making it less likely to cause confusion.)

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!