In JavaScript, throw means "throwing an exception"; the throw statement can create a custom error. When an error occurs, JavaScript will stop execution and throw an error message. The syntax is "throw expression; ".
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
The throw statement throws an error.
When an error occurs, JavaScript will stop execution and throw an error message.
The technical term to describe this situation is: JavaScript will throw an error.
throw statement creates a custom error.
The technical term is: Throw an exception.
Exceptions can be JavaScript strings, numbers, logical values, or objects:
throw "Too big"; // 抛出文本 throw 500; // 抛出数字
If you use throw with try and catch, you can control the program flow and generate custom errors information.
The syntax is:
throw expression;
where expression represents the exception thrown,
Related recommendations: javascript learning tutorial
The above is the detailed content of What does throw mean in javascript. For more information, please follow other related articles on the PHP Chinese website!