Frontend Simplified

Level up your frontend skills with “Frontend Simplified.” We provide roadmaps, interview prep, in-depth articles, and case studies covering Advanced JavaScript, React, Angular, and frontend system design to help you advance your career.

Member-only story

How to handle BigInt in Javascript: The missing numbers

Vamsi Krishna Kodimela
Frontend Simplified
3 min readAug 19, 2024

--

Just imagine, your APIs are returning a huge number like 900719925474099999, but after JSON parsing the response, you received 900719925474100000.

let x=900719925474099999;
console.log(x); // Console: 900719925474100000

let y=900719925474099999n;
console.log(y); // Console: 900719925474099999

This is going to have a huge impact on business and computation. We recently faced this situation. And appending n at the end of the number will solve this issue. But at the end?

Let’s find out:

  • What is happening here in the background?
  • Why appending n at the end solving this issue?
  • How have we handled it for our use case?
  • What are some of the best and most practical ways to handle this situation?

Introduction

Javascript uses a common number type for integer and float types. In JavaScript, all numbers are stored in a 64-bit floating-point format (IEEE 754 standard). As a result, the number type can support a range of numbers between -(2⁵³-1) and (2⁵³-1). This range is defined by two constants and…

--

--

Frontend Simplified
Frontend Simplified

Published in Frontend Simplified

Level up your frontend skills with “Frontend Simplified.” We provide roadmaps, interview prep, in-depth articles, and case studies covering Advanced JavaScript, React, Angular, and frontend system design to help you advance your career.

Responses (1)