Table of Contents
Null in Solidity overview
We don’t have the concept of undefined or null in Solidity. Instead, we have a default or zero concept. By default, each value, variable, or object gets a slot in memory once it is created, filled by the default value, for example, zero.
Different programming languages support the concept of
Let’s explore the default values of different types in Solidity.
Non-dynamic sized types
Non-dynamic type variables are the static type variables. Meaning we cannot change the size of the variables. They have fixed sizes that are not changeable. Static-type variables have straightforward default values.
uint256have a default value of
boolhave a default value of
addresstype has a default value of zero address that is
structtype has a default value of all its data members’ default types coupled in a tuple.
Dynamic sized types
Dynamic-sized type variables are the ones that can change their sizes. The sizes of these variables depend on the data they’re assigned. For example, an array can be of length 10 or length 1000.
stringtype has an empty string default value.
- The array’s default value is an empty array.
bytedefault value is empty or no
🔥 Check this course out: Create Your Own Ethereum Token in Just 30 Mins
Null in Solidity conclusion
Solidity has this weird feature where it doesn’t support undefined values. In some cases, having the undefined value is beneficial, while in others it is not. In either case, we’ll have to learn to cater to this problem, learn the default values of each type, and then work with them accordingly.
Try it out, ask any question, and let us know how it went by tagging Metaschool on Social Media.
Follow us on –
🔮Twitter – https://twitter.com/0xmetaschool
🔗LinkedIn – https://www.linkedin.com/company/0xmetaschool/