What is negative infinity in JS?

What is negative infinity in JS?

Syntax:
Number.NEGATIVE_INFINITY;

It’s common to use extreme values as a starting point for functions finding the maximum in a set of data. In this case, because elements don’t have a height less than 0 , it isn’t necessary, but provides better understanding once you’ve seen this concept before.

Consider the following arbitrary example.

var data = [ 1, 5, -10000, 50, 1240 ];

function maxData(data) {
    var max = Number.NEGATIVE_INFINITY;

    for (var i = 0; i < data.length; ++i)
        if (data[ i ] > max)
            max = data[ i ];

    return max;
}

This works great in JavaScript because any value compared to Math.NEGATIVE_INFINITY will be greater.