We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Error Object

Errors in JavaScript, like Go, are called Errors. It sure beats a silly name like "Exceptions"...

The most important property on the built-in error object is the message property: which should be a human-readable description of the error.

const err = new Error("We've run out of baked salmon");
console.log(err.message);
// We've run out of baked salmon

Assignment

Error messages at Textio have Error: in front of them. Convenient, right? Wrong. The devs keep forgetting to add it, so upper management has come up with a brilliant plan. A factory function that takes a string and returns a new Error object with 'Error: ' prepended to the message.

For example:

const err = createError("Boots is hungry");
console.log(err.message);
// Error: Boots is hungry

Surely this will solve all of their problems.