How is this :

function myFunc() returns(uint a){}

different from this:

function myFunc() returns(uint){}

4 Answers 4


Its purpose is two-fold:

Firstly, to serve as a visual aid to deciphering the meaning of a return value by simply looking at the function signature.

Secondly, it does not require one to initialize a given variable in the code OR explicitly return the value itself, for example:

function calculateSum(uint a, uint b) pure returns (uint sum) {
    sum = a + b;

is equivalent to:

function calculateSum(uint a, uint b) pure returns (uint) {
    uint sum = a + b;
    return sum;
  • 2
    Didn't you make a little typo in the second function? You kept returns (uint sum) while it should really just be returns (uint) Dec 23, 2020 at 10:11

It does not change the result of your program.

One of its purposes is to help remember what a function returns. For example:

function getTimeSinceAdded() return (uint seconds){...}

Now you only need to look at one line of code to know that the return value is in seconds, you don't need to read the function.

Another example is if you have multiple return values:

function myFunc() returns(uint, uint, uint){}

function myFunc() returns(uint timestamp, uint ethers, uint userID){}

Giving the return values names again makes it much easier to read what is returned and in which order.


Like @hcaw said, the other purpose is so you don't have to use the return statement. Instead, you can assign each return value separately:

function myFunc() returns(uint timestamp, uint ethers, uint userID)
    timestamp = 4;
    // some code...
    ethers = 1 ether;
    // some more code...
    userID = 4;
  • Side note: seconds is a reserved keyword, so your first example would not even compile. Feb 27, 2019 at 12:49

i benefited from this feature whenever i called functions from an external client such as web3 or ethers, the returned object has named properties, instead of iterating over the object properties to get their values, you just destructure the object with the names


FYI, the syntax was deprecated in 0.5.0: https://docs.soliditylang.org/en/latest/050-breaking-changes.html#syntax ("Function types with named return values are now disallowed.")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.