Functions in solidity
Functions in solidity
function in javascript
function in solidity
Similarities between two functions
- Both has function keyword
Let's look what are the differences between them:
-
first of all we can see returns keyword and inside the parenthesis data type of return value.
-
Second thing to notice is that in arguments in solidity has it's data types also
Let's breakdown function in solidity
- function keyword
- public keyword
- returns (uint256)
- pure function type
function keyword is used to declared a function.
public is the visibility of the function (from where this function can be called).
returns keyword is telling that this function returns a value and uint256 is the data type of value
Why parenthesis on (uint256)? This has parenthesis because a function can returns multiple values in a tupple (in parenthesis.)
There are two more keyword you can see in function which are function type keyword
- view
- pure
view - Function only reading variables from the contract but not changing it's values. Read only.
pure - Function neither read variables from the contract nor chages variable values. It does not touch contract variables nor see.
How do I return multiple values? You can return multiple values from function in tupple (inside parenthesis).
Do you know you can declare function with same name with different argument solidity will not complain?
let's see how?