- Solidity is statically types e.g
uint256 value
, you need to declare types - This is the order of precedence of operations
- The concept of undefined of null DOES NOT EXIST in solidity
- Newly declared variables always have a default value dependent on its type
- To handle unexpected values, you shout use the
revert()
function, to revert the whole transaction, or return a tuple with a secind bool value denoting success(value, bool) =
- Value Types:
- Booleans: True of False
- Opearators:
-
!
- logical negation -
&&
- logical conjunction, and -
||
- logical disjuntion or -
==
- equality -
!=
- inequalityNote: The operators
||
and&&
apply the common short-circuitung rules. This means that expressiongf(x) || g(y)
, iff(x)
evaluates to true, g(y)will not be evaluated even if it may have side-effects.
-
- Integers
-
int
oruint
signed and unsigned integers of various sizes,uint8
touint256
in steps of8
- Operators:
- Comparisons:
<=
,<
,==
,!=
,>=
,>
- evaluate tobool
- Bit operators:
&
,|
,^
(exclusive or - xor),~
(bitwise negation) - Shift operators:
<<
,>>
The righy operand must be of uinsigned type, trying to shift by signed type will produce a compilation error.
x << y
$\equiv$ x * 2**y
,x >> y
$\equiv$ x / 2**y
, Warning: Overflow checks are never performed for shift operations as they are done for arithmetic operations. Instead the result is truncated. - Arithmetic operators:
+
,-
,-
unary (only for signed integers),*
,/
,%
,**
- for integer X,
type(X).min
andtype(X).max
for minimum and maximum values presentable by the type
- Comparisons:
-