Member-only story
Absence of Null in Solidity
Solidity programming language doesn’t have the nullability feature
One of the weirdest Solidity programming language’s quirks is the absence of null. Coming from Swift, where nullability is one of the core building blocks, it felt foreign. At first, I didn’t understand how to code without such a useful feature. This post elaborates on how to find a way around that in Solidity when building smart contracts.
Concept of undefined
The concept of undefined
, null
, nil
, None
, etc. exists in languages like JavaScript, Java, Python, Swift, .etc. but it does not exist in Solidity.
In Solidity, we can call it zero or default value concept instead. That is because each value gets a slot in the memory once it is created, and should contain something.
Default values
To talk about default values, we should split the Solidity types into two blocks:
- dynamically sized types like
string
,bytes
, and arrays; - non dynamically sized types like
int
,bool
andaddress
.
Non dynamically sized types
With non-dynamically sized types, the game is pretty straightforward. Here are the default values for those: