concept return keyword in category dart

appears as: return keyword
Dart in Action

This is an excerpt from Manning's book Dart in Action.

Longhand functions, on the other hand, always return the default null if you don’t actively return another value by using the return keyword. The return keyword can also specify an optional value to return (which replaces the null default), such as in this longhand mix() function:

return item1 + item2;

When return is used, it immediately returns the result to the calling code. If a longhand function does explicitly return a value with the return keyword, then the function returns null. Figure 4.2 shows the return keyword used in a longhand function and the expression that’s evaluated for a return value in the shorthand style. It also shows a common error that can occur in your code: forgetting to use the return keyword.

Figure 4.2. Longhand functions require the return keyword to return a value, whereas shorthand functions return the result of their single-line expression automatically.
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage