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

287
Visualizações
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 Respostas
Responde à pergunta

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 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