JS Built-ins
ReferenceErrorintermediate

ReferenceError β€” throw and catch

πŸ“– Usage Example
try {
  null.property
} catch (e) {
  // this is a TypeError, not ReferenceError
  e instanceof TypeError  // β†’ true
}

Distinguish ReferenceError (undeclared variable) from TypeError (wrong type operation).

Catching ReferenceError

You can manually throw and catch a ReferenceError.

Challenge: Throw a ReferenceError and return its .name from the catch block.

πŸ’‘ Hints (1)
  • β€’ Use throw new ReferenceError(message) to manually throw a ReferenceError.