Toán tử + ép chuỗi sang số gây mất độ chính xác với số lớn. Nên dùng BigInt().
Mã thực hiện
var stringValue1 = "100";
console.log("The integer value=");
console.log(+stringValue1);
var stringValue2 = "2312123211345545367";
console.log("Loss of precision with + operator..");
console.log(+stringValue2);
const storeLongInteger = BigInt("2312123211345545367");
console.log("No loss of precision with BigInt()");
console.log(storeLongInteger);
Kết quả
The integer value= 100 Loss of precision with + operator.. 2312123211345545000 No loss of precision with BigInt() 2312123211345545367n