Как работает return в javascript
Перейти к содержимому

Как работает return в javascript

  • автор:

JavaScript return

The return statement stops the execution of a function and returns a value.

Read our JavaScript Tutorial to learn all you need to know about functions. Start with the introduction chapter about JavaScript Functions and JavaScript Scope. For more detailed information, see our Function Section on Function Definitions, Parameters, Invocation and Closures.

Syntax

Parameters

Parameter Description
value Optional.
The value to be returned.
If omitted, it returns undefined

More Examples

Calculate the product of two numbers and return the result:

// Call a function and save the return value in x:
var x = myFunction(4, 3);

function myFunction(a, b) <
// Return the product of a and b
return a * b;
>

Related Pages

Browser Support

return is an ECMAScript1 (ES1) feature.

ES1 (JavaScript 1997) is fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

Unlock Full Access

COLOR PICKER

colorpicker

Join our Bootcamp!

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials
Top References
Top Examples
Get Certified

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *