Eclecticist Eclecticist - 2 months ago 6x
Javascript Question

What is the difference between throw Error and console.error

What is the difference between these two statements, and is there a good reason to use one over the other?

throw Error("msg");

In my limited experience, I've only really seen
throw Error()
used. Is there any particular reason why?

Also, is there an equivalent to
in the same fashion?


throw ... raises an exception in the current code block and causes it to exit, or to flow to next catch statement if raised in a try block.

console.error just prints out a red message to the browser developer tools javascript console and does not cause any changes of the execution flow.