Multiple choice technology web technology

To what value will the following expressions evaluate in the JavaScript console? typeof 1/0

  1. Infinity

  2. NaN

  3. number

  4. null

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The expression typeof 1/0 is parsed as (typeof 1) / 0 due to operator precedence. The typeof operator returns the string "number" for the value 1. Then JavaScript attempts to divide this string by 0, which coerces "number" to NaN (since it's not a valid numeric string). Finally, NaN / 0 evaluates to NaN. This is different from simply evaluating 1/0, which would give Infinity.