JS Built-ins
Errorintermediate

Error types β€” RangeError on invalid array length

πŸ“– Usage Example
class NetworkError extends Error {
  constructor(msg) { super(msg); this.name = 'NetworkError' }
}

Extend Error to create application-specific error types with custom names.

RangeError on new Array(-1)

Creating an array with a negative length throws a RangeError.

Challenge: Verify the error is thrown.

πŸ’‘ Hints (1)
  • β€’ Array() with a negative length argument throws a RangeError.