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

210
Vistas
Why are these two values different?

I recently had a lecture where we covered BigInts and how to declare them using either the constructor or appending an 'n' to the end of the number. I felt as though I understood the lecture well, until I encountered this strange behavior.

Could someone explain to me why there's a difference here?

console.log(239723948723409274092834987230917298720394203874n);
console.log(BigInt(239723948723409274092834987230917298720394203874));

//OUTPUT
239723948723409274092834987230917298720394203874n
239723948723409282517569648409973454535932248064n

It's the same number in both use cases, but the output is different. I suspect that this is actually appropriate behavior because the argument passed to the constructor has to be calculated by the engine before the constructor uses it?

I'm not sure if that's correct though, so that's why I'm here.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Numeric constants (either plain numbers or big int values with the trailing n) are parsed and evaluated as per their type before the program even runs. If you put a big int constant in your program, the parser creates code that runs with a big int value. If you put a plain number in your code, the parser creates a plain 64 bit floating point number, like all old-school JavaScript numeric values.

Thus when you call BigInt() with a constant that does not have the trailing n, which would tell the parser to make a big int and not a plain number, you're creating an expression that's evaluated before the function call. It's a plain number, so you lose a whole lot of precision before your new big int value is even created.

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