How does -Infinity work?

    STACKOVERFLOW = [];
    turkeycheck = Math.max.apply(null, STACKOVERFLOW);
    if(!turkeycheck){
         // See Below
    }

console.log(turkeycheck);
console.log(turkeycheck.length);

      

Also can be seen here: http://jsfiddle.net/L4zgfcmz/5/

Curious why it (!turkey)

doesn't get hit, but using turkeycheck.length

shows it undefined? If it's undefined doesn't mean it's false?

Also, if it turkey

is console logging -Infinity

, shouldn't the length turkeycheck

become 11?

I'm just confused as to why the parameter turkey

is set to -Infinity, but then it becomes undefined

.

+3


source to share


1 answer


-Infinity

- numeric value. Numeric values ​​have no property .length

, so trying to read from it will return undefined

. The value stored in your variable turkeycheck

remains unchanged, and if you try to write its value after trying to register its length, you will still be shown the value -Infinity

.



var n = 1;
console.log(n.length); // undefined
console.log(n);        // 1

      

+4


source







All Articles