JavaScript Tutorial

The language for programming web pages.

JS Errors

JavaScript Error Handling

JavaScript uses try...catch...finally to handle runtime errors gracefully without crashing the program.

Error Types:

  • SyntaxError — Invalid code
  • ReferenceError — Variable not defined
  • TypeError — Wrong type operation
  • RangeError — Value out of range
  • URIError — Bad URI encoding

Custom Errors:

Use throw new Error("message") to throw custom errors.

Try It Yourself

Edit the code below and click Run to see the result live.

Source Code
Result
Topics