Skip to main content
1 of 3

This boils down to the difference between the "fetch!" and "fetches" at the dog park. Respectively an order and a statement.

"return X" is an imperative AKA an order. Like in linguistics, it says "you (your function) better return that thing that needs returning and that's an order!".

This order is generally found at the very end of a function and means "now that you're done processing X, return it to whatever line of code called this function you're currently in".

Meanwhile, "returns X" is a declarative AKA a statement of a fact. Like in linguistics, it is a statement that "this thing (your function) is expected to return something once it's done doing its thing.

This statement is found in the declaration of a function and means "once done, this function returns one or more things of the following types to whoever called this function".

So if you're declaring a function and you want whoever reads your code (including and especially your future self) to know at a glance what this function returns, then declare/state it:

function myFunction returns (typeOfMyThingReturnedByThisFunction easyToUnderstandNameOfMyThingReturnedByThisFunction) { blah blah blah the body of my function goes here }

To actually return the thing the thing that this function returns, you issue an order by telling the function "hey, function, return the thing I want you to return!" as follows:

function myFunction 
returns (
typeOfMyThingReturnedByThisFunction easyToUnderstandNameOfMyThingReturnedByThisFunction
) 
{
return easyToUnderstandNameOfMyThingReturnedByThisFunction;
}

Example:

/* My function returnS a uint called theNumberFour which is probably the number 4 */
function myFunction returns (uint theNumberFour) {
/* "Hey, function, please return the number 4" */
return 4;
}