Home > Article > Web Front-end > What is the meaning of return in javascript
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.
#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!