The examples in this article describe the usage of return in JavaScript. Share it with everyone for your reference, the details are as follows:
return can accept the return value in the function, provided that there is a return statement in the function.
The following is a small application example:
<html> <head> <script type='text/javascript'> function linkPage(){ alert('You Clicked??'); return false; } </script> </head> <body> <A href='http://www.baidu.com' name='link' onclick="return linkPage()"> Click Me </A> </body> <html>
This example is very simple. If you click Click Me, an onclick event will be triggered. The onclick event calls the linkPage function and accepts its return value.
The page will pop up an alert prompt box and accept the return value of linkPage. If the value is true, it will jump to the Baidu page, but the return value is false, so there is no movement on the page.
Sometimes this return is unnecessary, presence and absence are the same effect. That is, when the function linkPage has no return value.