Functions
Function Declarations
function functionName(parameterList): ReturnType {
// Function body
}
parameterList
is a comma-separated list of parameters with their types.ReturnType
is optional; if omitted, the function does not return a value.
Parameters
Parameters are declared with their name and type.
function add(a: uint256, b: uint256): uint256 {
return a + b;
}
Return Types
Specify the return type after the parameter list and a colon.
function isPositive(number: uint256): bool {
// Function body
}
Note: The bool
type may not be fully implemented yet; currently, functions can return uint256
.
Return Statements
Use the return
keyword to return a value from a function.
return expression;
Last updated