为什么下面的代码输出结果是相等的?如何比较?
var num1 = 340282000000000000000000000000000000001
var num2 = 340282000000000000000000000000000000000 // 3.402823E+38
if(num1 == num2) {
console.log('num1 equal to num2');
} else if(num1 > num2) {
console.log('num1 bigger than num2');
} else {
console.log('num1 lower than num2')
}
BigInt
:
var num1 = 340282000000000000000000000000000000001n;
var num2 = 340282000000000000000000000000000000000n;
if(num1 == num2) {
console.log('num1 equal to num2');
} else if(num1 > num2) {
console.log('num1 bigger than num2');
} else {
console.log('num1 lower than num2')
}