Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

Negative Infinity ใน JavaScript คืออะไร?

Property Number.NEGATIVE_INFINITY แทนค่า negative Infinity ค่าที่เกิน maximum value ใน JavaScript จะกลายเป็น negative infinity

ตัวอย่าง

function checkInfinity(smallNumber) {    if (smallNumber === Number.NEGATIVE_INFINITY) {       return 'Process number as -Infinity';    }    return smallNumber; } console.log(checkInfinity(-Number.MAX_VALUE)); console.log(checkInfinity(-Number.MAX_VALUE * 2));

ผลลัพธ์

-1.7976931348623157e+308 "Process number as -Infinity"

รายละเอียดเพิ่มเติมที่ MDN docs

หมายเหตุ - ค่า Number.NEGATIVE_INFINITY เท่ากับค่าลบของ global object's Infinity property