I see it in some contract examples, but it doesn't look like it has the exact same purpose as regular JavaScript. Can it be used to initialize variables in a specific scope without declaring a type?


1 Answer 1


From the docs:

Type Deduction

For convenience, it is not always necessary to explicitly specify the type of a variable, the compiler automatically infers it from the type of the first expression that is assigned to the variable:

uint24 x = 0x123;
var y = x;

Here, the type of y will be uint24. Using var is not possible for function parameters or return parameters.

This is also a must for Destructuring Assignments

function f() public pure returns (uint, bool, uint) {
        return (7, true, 2);
var (x,y,z) = f(); //Multi-Return from Fx

(x,y) = (y,x) //Swap Values

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.