Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update method-calls.markdown to include 'returning values' section. #1173

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions doc/site/method-calls.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,30 @@ These are equivalent to method calls whose signature is `[_]=(_)` and whose
arguments are both the subscript (or subscripts) and the value on the right-hand
side.

## Returning values

The body of a method is a [block](syntax.html#blocks). If it is a single
expression—more precisely if there is no newline after the `{` —
then the method implicitly returns the value of the expression.

Otherwise, the body returns `null` by default. You can explicitly return a
value using a `return` statement. In other words, these two methods do the
same thing:

<pre class="snippet">
method1() { "return value" }

method2() {
return "return value"
}
</pre>


However, it would be an error to include a `return` statment in method1():
<pre class="snippet">
method1() { return "return value" } //> Error at 'return': Expected expression.
</pre>

<br><hr>
<a class="right" href="control-flow.html">Control Flow &rarr;</a>
<a href="maps.html">&larr; Maps</a>
Loading