Home > Web Front-end > JS Tutorial > What is the meaning of return in javascript

What is the meaning of return in javascript

王林
Release: 2023-01-07 11:42:20
Original
2946 people have browsed it

The meaning of return in JavaScript is to terminate the execution of the function and return the value of the function, such as [return a * b;], which means returning the product of a and b.

What is the meaning of return in javascript

#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.

The return statement in JavaScript can terminate the execution of the function and return the value of the function.

Let’s take a look at its syntax format:

return [[expression]];
Copy after login

Return the value of expression. If ignored, that is, return; returns undefined.

Look at the specific code example:

Calculate the product of two numbers and return the result:

var x = myFunction(4, 3);        // 调用函数,将返回值赋予 x 变量
function myFunction(a, b) {
    return a * b;                // 函数返回 a 和 b 的乘积
}
Copy after login

xThe output result is:

12
Copy after login

Related video tutorials Recommended: javascript video tutorial

The above is the detailed content of What is the meaning of return in javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template