typeof Infinity and typeof Number.Infinity

33 views
Skip to first unread message

Christoph Bussler

unread,
Dec 5, 2012, 7:41:57 PM12/5/12
to v8-u...@googlegroups.com
Hi,

as expected, typeof Infinity is 'number'. However, typeof Number.Infinity is 'undefined'. Why is that?

typeof Number.POSITIVE_INFINITY and typeof Number.NEGATIVE_INFINITY are both 'number', too. So I would expect typeof Number.Infinity to be 'number' also.

Thanks.

Paul Harris

unread,
Dec 5, 2012, 9:36:00 PM12/5/12
to v8-u...@googlegroups.com
I may be wrong, but 'Infinity' is like null and Undefined - a magic reserved word.
It is not a property of the 'Number' object,

So Number.Infinity is Undefined in the same way as Number.whatever
"whatever" is not a property on Number either, so it is also Undefined.

Rick Waldron

unread,
Dec 5, 2012, 9:49:58 PM12/5/12
to v8-u...@googlegroups.com
On Wed, Dec 5, 2012 at 9:36 PM, Paul Harris <harr...@gmail.com> wrote:
I may be wrong, but 'Infinity' is like null and Undefined - a magic reserved word.
It is not a property of the 'Number' object,

Confirmed. There is no such property of the global Number object.

Rick

So Number.Infinity is Undefined in the same way as Number.whatever
"whatever" is not a property on Number either, so it is also Undefined.


On Thursday, December 6, 2012 8:41:57 AM UTC+8, Christoph Bussler wrote:
Hi,

as expected, typeof Infinity is 'number'. However, typeof Number.Infinity is 'undefined'. Why is that?

typeof Number.POSITIVE_INFINITY and typeof Number.NEGATIVE_INFINITY are both 'number', too. So I would expect typeof Number.Infinity to be 'number' also.

Thanks.

chbussler

unread,
Dec 6, 2012, 11:51:42 AM12/6/12
to v8-u...@googlegroups.com
Thanks for the quick reply. WebStorm suggests in the auto completion that it is. I'll circle back with them on that.

Yang Guo

unread,
Dec 10, 2012, 5:08:36 AM12/10/12
to v8-u...@googlegroups.com
The ECMA-262 5.1 spec expects the Number object to have the properties MAX_VALUE, MIN_VALUE, NAN, POSITIVE_INFINITY and NEGATIVE_INFINITY. Any other property is therefore undefined, so that (Number.Infinity === undefined) evaluates to true.

Yang
Reply all
Reply to author
Forward
0 new messages