Eclecticist Eclecticist - 1 year ago 96
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download