Skip to main content
Commonmark migration
Source Link

If null is a primitive, why does typeof(null) return "object"?

Because the spec says so.

11.4.3 The typeof Operator

The production UnaryExpression : typeof UnaryExpression is evaluated as follows:

 
  1. Let val be the result of evaluating UnaryExpression.
  2. If Type(val) is Reference, then
       a. If IsUnresolvableReference(val) is true, return "undefined".
       b. Let val be GetValue(val).
  3. Return a String determined by Type(val) according to Table 20.

enter image description here

If null is a primitive, why does typeof(null) return "object"?

Because the spec says so.

11.4.3 The typeof Operator

The production UnaryExpression : typeof UnaryExpression is evaluated as follows:

 
  1. Let val be the result of evaluating UnaryExpression.
  2. If Type(val) is Reference, then
       a. If IsUnresolvableReference(val) is true, return "undefined".
       b. Let val be GetValue(val).
  3. Return a String determined by Type(val) according to Table 20.

enter image description here

If null is a primitive, why does typeof(null) return "object"?

Because the spec says so.

11.4.3 The typeof Operator

The production UnaryExpression : typeof UnaryExpression is evaluated as follows:

  1. Let val be the result of evaluating UnaryExpression.
  2. If Type(val) is Reference, then
       a. If IsUnresolvableReference(val) is true, return "undefined".
       b. Let val be GetValue(val).
  3. Return a String determined by Type(val) according to Table 20.

enter image description here

added 72 characters in body
Source Link
Matt Ball
  • 360.9k
  • 102
  • 655
  • 725

If null is a primitive, why does typeof(null) return "object"?

Because the spec says so.

11.4.3 The typeof Operator

The production UnaryExpression : typeof UnaryExpression is evaluated as follows:

  1. Let val be the result of evaluating UnaryExpression.
  2. If Type(val) is Reference, then
           a. If IsUnresolvableReference(val) is true, return "undefined".
           b. Let val be GetValue(val).
  3. Return a String determined by Type(val) according to Table 20.

enter image description here

enter image description here

If null is a primitive, why does typeof(null) return "object"?

Because the spec says so.

11.4.3 The typeof Operator

The production UnaryExpression : typeof UnaryExpression is evaluated as follows:

  1. Let val be the result of evaluating UnaryExpression.
  2. If Type(val) is Reference, then
      a. If IsUnresolvableReference(val) is true, return "undefined".
      b. Let val be GetValue(val).
  3. Return a String determined by Type(val) according to Table 20.

enter image description here

If null is a primitive, why does typeof(null) return "object"?

Because the spec says so.

11.4.3 The typeof Operator

The production UnaryExpression : typeof UnaryExpression is evaluated as follows:

  1. Let val be the result of evaluating UnaryExpression.
  2. If Type(val) is Reference, then
         a. If IsUnresolvableReference(val) is true, return "undefined".
         b. Let val be GetValue(val).
  3. Return a String determined by Type(val) according to Table 20.

enter image description here

added 72 characters in body
Source Link
Matt Ball
  • 360.9k
  • 102
  • 655
  • 725

If null is a primitive, why does typeof(null) return "object"?

Because the spec says so.

11.4.311.4.3 The typeof Operator

The production UnaryExpression : typeof UnaryExpression is evaluated as follows:

  1. Let val be the result of evaluating UnaryExpression.
  2. If Type(val) is Reference, then
     a. If IsUnresolvableReference(val) is true, return "undefined".
     b. Let val be GetValue(val).
  3. Return a String determined by Type(val) according to Table 20.

enter image description here

If null is a primitive, why does typeof(null) return "object"?

Because the spec says so.

11.4.3 The typeof Operator

The production UnaryExpression : typeof UnaryExpression is evaluated as follows:

  1. Let val be the result of evaluating UnaryExpression.
  2. If Type(val) is Reference, then
     a. If IsUnresolvableReference(val) is true, return "undefined".
     b. Let val be GetValue(val).
  3. Return a String determined by Type(val) according to Table 20.

enter image description here

If null is a primitive, why does typeof(null) return "object"?

Because the spec says so.

11.4.3 The typeof Operator

The production UnaryExpression : typeof UnaryExpression is evaluated as follows:

  1. Let val be the result of evaluating UnaryExpression.
  2. If Type(val) is Reference, then
     a. If IsUnresolvableReference(val) is true, return "undefined".
     b. Let val be GetValue(val).
  3. Return a String determined by Type(val) according to Table 20.

enter image description here

Source Link
Matt Ball
  • 360.9k
  • 102
  • 655
  • 725
Loading