Consider adding an alternative to `typeof` that doesn’t include the legacy baggage of `typeof`

This alternative would return values closer to the Type abstract operation:

Type of val Result
Undefined "undefined"
Null "null"
Boolean "boolean"
Number "number"
String "string"
Symbol "symbol"
BigInt "bigint"
Object "object"

Additionally, this alternative would ignore the [[IsHTMLDDA]] internal slot.

typeof allows to distinguish between functions and non-functions, and is indeed the only way to do that reliably, although the Type abstract operation does not. That means that your new operator would not make typeof obsolete.

The two object kinds that I most often want to distinguish are functions and arrays, so that I suggest to add the following two cases:

  • "function"
  • "array" (currently testable through Array.isArray())
1 Like

Disambiguation between callables and constructors will be possible with Function.isCallable(…) and Function.isConstructor(…).

Also, Arrays should not be distinguished from plain objects in typeof, that’s what Array.isArray(…) is for.

Those aren’t unbreakable syntax, however, so robust code would continue to have to use typeof.