


Detailed explanation of the return function in Javascript and the usage of the javascript return keyword_javascript skills
The return in javascript has always been popular. Do you know about the function of return in javascript? Let me give you a detailed introduction in this article. The specific content is as follows:
Thereturn statement exits the current function and returns a value from that function.
Syntax:
return[()[expression][]];
The optional expression parameter is the value to be returned from the function. If omitted, the function returns no value.
Use the return statement to terminate the execution of a function and return the value of expression. If expression is omitted, or no return statement is executed within the function, the value undefined is assigned to the expression that called the current function.
The following example illustrates the use of the return statement:
function myfunction(arg, arg){ var r; r = arg * arg; return(r); }
return means returning from the called function to the calling function to continue execution. The return can be accompanied by a return value, which is specified by the parameter after return. Return is usually necessary because the calculation result is usually brought out through the return value when the function is called.
If you really don’t need the value returned by the function, you need to declare its type with void.
Supplement: If there is a return type definition before your function name, such as int, double, etc., it must have a return value. If it is void type, you don’t need to write return, but even if you write it, you can’t return a value:
The following is a non-void function:
int f() { int i=; return ; //return(i); //这样也可以 }
void type function:
void f()
{
int i=;
//return;//This is okay, you don’t need this sentence either
}
ps: The role of return in javascript
The return here contains some detailed knowledge:
For example: the difference between onClick='return add_onclick()' and onClick='add_onclick()'
JAVASCRIPT uses return when calling a function in an event to actually set the window.event.returnvalue.
This value determines whether the current operation continues.
When true is returned, the operation will continue.
When the return is false, the operation will be interrupted.
When executed directly (without return). window.event.returnvalue will not be set
So the operation will continue by default
Details are as follows:
For example:
When in Open
If the function add_onclick() returns true, then the page will open abc.htm
Otherwise, (return false), then the page will not jump to abc.htm, but will only execute the content in your add_onclick() function. (The control page in the add_onclick function will go to
Except abc.htm)
And Open
No matter what value add_onclick() returns, the page abc.htm will be opened after add_onclick is executed
Additional addition:
Onclick event is equivalent to onclick="return true/false"
Example:
function check() { if(obj.value=="" ) { window.alert("不能为空!"); obj.focus(); return false; } return true; }
The form will be submitted only when the calling method returns true, otherwise it will not be submitted. This is the submit button
-------------------------------------------------- -----------------------------------------------
There is no need to return when calling the js function, but the form cannot be submitted, so add a sentence in the js function
Example:
<script language="javascript"> function check() { if(obj.value=="" ) { window.alert("不能为空!"); obj.focus(); return false; } document.myform.submit(); return true; } </script>
Note: document.myform.submit(); must be before return true

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Data update problems in zustand asynchronous operations. When using the zustand state management library, you often encounter the problem of data updates that cause asynchronous operations to be untimely. �...
