Terminate function execution in javascript
This article mainly introduces how to terminate function execution in javascript. If you need it, you can refer to it for help.
1. if return is used to terminate a function, the instance is as
Validation methods submitted (compared by a single character):insert title here verifydate Commit Validation method (via regular expression)JS with pattern.test (need to verify string) pattern is regular expressioninsert title here verifydate
1. if return is used to terminate a function, the instance is as follows:Function testA (){Alert ('A ');Alert ('B ');Alert ('C ');}TestA (); program execution will pop up 'A', 'B', 'C' in sequence '.
Function testA (){Alert ('A ');Return;Alert ('B ')
1) Intro
Not long ago I set up a technology group in a MM asked a question like this, she posted the code as follows:
var a = 1;function hehe (){Window.alert (a);var a = 2;Window.alert (a);}Hehe ();
The results of the execution are as follows:
Web effects continue methods to terminate the current loop
The continue command terminates the current loop and then continues running from the next value.Instance:
Jump out of the loop
a Simple page
Example Two
The setTimeout and setInterval of JavaScript are two methods that can easily fool others' feelings, because we often think that the call will be executed in the established way. I think many people share the same feeling,
JavaScript timer that is
For example
Copy Code code as follows:
settimeout (function () {alert (' Hello! ');}, 0;
SetInterval (callbackfunction, 100);
It is assumed that the greeting method in settimeout is executed immediately, because it is not a
The setTimeout and setInterval of JavaScript are two methods that can easily fool others' feelings, because we often start to think that the call will be executed in the established way. I think many people share the same feeling. For example
The
The settimeout and setinterval of JavaScript are two easy ways to cheat people's feelings, because we start to think that the call will be executed in a way that I think a lot of people are feeling, like [JavaScript]
settimeout (function () {alert (
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.