Why are the results returned by the two operations inconsistent, and why is it not NaN?

var a = 9/0;
a;
Infinity
typeof a;
"number"



typeof 9/0;
NaN
typeof NaN
"number"
Mar.09,2021

priority ratio of

typeof


typeof (9pm 0) is' number'
Infinity is infinity, is a number


similar

var a = 1;
typeof a*1

 NaN
var a = 1;
typeof (a*1)
NUmber

the reason is that the parameters after typeof do not participate in the calculation, so typeof 9 Infinity 0, 9, typeof (0 he will not calculate the result, so NaN is not a number
after adding parentheses, it will first calculate, typeof (9 Infinity 0, and then typeof Infinity is Number

.

see MDN description

Key description on

MDN (clasp): the
typeof operator returns a string indicating the type of uncalculated Operand.

Menu