JS Built-ins
Errornamebeginner

Error.name β€” SyntaxError is 'SyntaxError'

πŸ“– Usage Example
class AppError extends Error {
  constructor(msg) { super(msg); this.name = 'AppError' }
}
new AppError('x').name  // β†’ 'AppError'

Set this.name in subclass constructors to give custom errors a meaningful name.

SyntaxError.name

new SyntaxError().name returns 'SyntaxError'.

Challenge: Verify the name.

πŸ’‘ Hints (1)
  • β€’ SyntaxError is thrown when invalid code or JSON is parsed.