1

I'm setting max to Infinity on this object:

let RANGE_DEFAULT_OPTIONS: any = { min: 0, max: Infinity };
console.log(RANGE_DEFAULT_OPTIONS); // {min: 0, max: null}

When the RANGE_DEFAULT_OPTIONS object is logged, it logs null for the max property.

Here's the Stackblitz Demo

Also this will log true:

console.log(RANGE_DEFAULT_OPTIONS.max === Infinity);

So are Infinity and null interchangeable?

Ole
  • 41,793
  • 59
  • 191
  • 359

2 Answers2

5

No, they’re not.

Normally, console.log(…) called with an object, prints the object intact:

enter image description here

const obj = { min: 0, max: Infinity };

console.log(obj);

In the case of StackBlitz, there’s probably a call to JSON.stringify(…) somewhere down there, which messes things up (which is sad, IMO):

enter image description here

Parzh from Ukraine
  • 7,999
  • 3
  • 34
  • 65
  • 1
    Yup, c.f. https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript for further context – Jonas Wilms Nov 01 '21 at 22:07
3

Here's the same code in a snippet you can run in your browser. As you can see, Infinity and null are not equal.

let RANGE_DEFAULT_OPTIONS = { min: 0, max: Infinity };
console.log(RANGE_DEFAULT_OPTIONS);
console.log('strict equality', Infinity === null);
console.log('loose equality', Infinity == null);
jsejcksn
  • 27,667
  • 4
  • 38
  • 62