Error function to make our own error object with a message that is unique to our program!
console.log(Error('Your password is too weak.')); // Prints: Error: Your password is too weak.
Error function takes an argument of a string which becomes the value of the error’s
message property. In the code snippet above, we used the
Error function to create an error object that has the message
'Your password is too weak.'.
You might also see errors created with the
new keyword. Both methods will lead to the same functionality. Take a look:
console.log(new Error('Your password is too weak.')); // Prints: Error: Your password is too weak.
Keep in mind that creating an error is not the same as throwing an error. A thrown error will cause the program to stop running. We cover how to throw our created errors in the next exercise!
At the top of main.js add a
console.log() that prints an error with the message
'User missing name'.
After running the code, take note of the
console.log() at the bottom of main.js and if that line of code still runs.