There are several possibilities for terminating JS operations:
1. There are two ways to terminate a function's operation
(1) Using return in the function, the function terminates execution when the return is encountered, and control continues to run down
(2) Use Try-catch exception handling in function, throw exception with throw when end is required
function Getrectarea (width, height) { if (IsNaN (width) | | IsNaN (height)) { throw "Parameter is not a number!"; }} try { Getrectarea (3, ' A ');} catch (e) { console.log (e); Expected output: "Parameter is not a number!"}
2. The way to stop animation effects from running is by using the Stop method
(1) Stop ([Clearqueue], [gotoend]): Stops all animations that are running on the specified element
(2) If there is an animation waiting to be executed in the queue (and Clearqueue is not set to true), it will be executed immediately
3. How to terminate form submission: Use return false in form submission events, prevent form submission
4. How to terminate the timing function execution: Use Window.clearinterval (Timer object) or Window.cleartimeout (Timer object), can terminate the executing timer
How to implement JS termination