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

What is the meaning of return in javascript

王林
王林Original
2021-07-08 13:54:522928browse

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]];

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 的乘积
}

xThe output result is:

12

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!

Statement:
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
Previous article:what is javascript engineNext article:what is javascript engine