Grokking Advanced JavaScript
Vote

0% completed

​

The throw Statement

JSON.parse reports broken order text by throwing a SyntaxError. An order can also be valid JSON and still be wrong, for example {"item": "book", "quantity": 0}. JSON.parse accepts that text without complaint, because a quantity of zero is not a JSON problem. To reject it, your own function must report the error, and it does that with the throw statement.

The throw statement

throw expression;

The throw statement stops the current code immediately, and the engine then treats the value of expression exactly like an error that it threw itself. If the `throw

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content