Like Python or any other language why does Solidity avoid having the Null and undefined properties?

  • What for?.......... Jun 14, 2020 at 14:13
  • @goodvibration just want to learn logic behind not using Null and undefined!! Jun 14, 2020 at 14:56
  • Just asked what you were hoping to use it for, so I could suggest alternatives. undefined doesn't exist in any other language that I'm aware of, with the exception of Javascript (and Python if you consider None equivalent). So you could just as well as that about C, C++, Java, etc. Jun 14, 2020 at 15:04

1 Answer 1


A variable cannot be set as null or undefined because the EVM does not have a concept of null. When a variable is declared, it initially contains the zero-equivalent of it's given type.

From the Solidity documentation on types:

The concept of “undefined” or “null” values does not exist in Solidity, but newly declared variables always have a default value dependent on its type.

And on declarations:

A variable which is declared will have an initial default value whose byte-representation is all zeros. The “default values” of variables are the typical “zero-state” of whatever the type is. For example, the default value for a bool is false. The default value for the uint or int types is 0. For statically-sized arrays and bytes1 to bytes32, each individual element will be initialized to the default value corresponding to its type. For dynamically-sized arrays, bytes and string, the default value is an empty array or string. For the enum type, the default value is its first member.

  • I want to know why we don't use NULL and UNDEFINED? Jun 14, 2020 at 14:47
  • 2
    @HaseebSaeed: You don't use them, because the language doesn't define them. The language doesn't define them, because just like many other languages, it does not consider them a necessary requirement. For example, C does not define them either. C++ and Java define null, but they do not define undefined. And there are many similar examples. So the question seems rather pointless. In contrast, you could ask what is the Solidity equivalent for these two concepts. But you'll need to show an example where they are actually needed. Jun 14, 2020 at 15:07
  • @goodvibration thanks for your answer btw. I thought it could be an good idea to know the theoretical side of this issue. Jun 14, 2020 at 15:13
  • 1
    @HaseebSaeed: If I were to speculate, then the theory behind this is that the authors of the language did not see any practical use of these concepts. That's why I said you should show a use-case (or a potential use-case) for them, so that readers of your question will be able to refer to it. Jun 14, 2020 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.