{"id":7182,"date":"2024-02-09T08:07:01","date_gmt":"2024-02-09T08:07:01","guid":{"rendered":"https:\/\/metaschool.so\/articles\/?p=7182"},"modified":"2024-02-09T08:12:43","modified_gmt":"2024-02-09T08:12:43","slug":"null-in-solidity","status":"publish","type":"post","link":"https:\/\/metaschool.so\/articles\/null-in-solidity\/","title":{"rendered":"Is There a Null in Solidity Programming Language?"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_56_1 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/metaschool.so\/articles\/null-in-solidity\/#Null_in_Solidity_overview\" title=\"Null in Solidity overview\">Null in Solidity overview<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/metaschool.so\/articles\/null-in-solidity\/#Non-dynamic_sized_types\" title=\"Non-dynamic sized types\">Non-dynamic sized types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/metaschool.so\/articles\/null-in-solidity\/#Dynamic_sized_types\" title=\"Dynamic sized types\">Dynamic sized types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/metaschool.so\/articles\/null-in-solidity\/#Null_in_Solidity_conclusion\" title=\"Null in Solidity conclusion\">Null in Solidity conclusion<\/a><\/li><\/ul><\/nav><\/div>\n\n<h2 class=\"wp-block-heading\" id=\"null-in-solidity-overview\"><span class=\"ez-toc-section\" id=\"Null_in_Solidity_overview\"><\/span>Null in Solidity overview<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We don\u2019t have the concept of undefined or null in <a href=\"https:\/\/metaschool.so\/articles\/guide-solidity-contracts\/\">Solidity<\/a>. 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.<\/p>\n\n\n\n<p>Different programming languages support the concept of&nbsp;<code>undefined<\/code>,&nbsp;<code>null<\/code>,&nbsp;<code>Null<\/code>,&nbsp;<code>NaN<\/code>,&nbsp;<code>nil<\/code>,&nbsp;<code>None<\/code>, etc, for example, Python, C++, Javascript, and Go, but Solidity doesn&#8217;t.<\/p>\n\n\n\n<p>Let\u2019s explore the default values of different types in Solidity.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"non-dynamic-sized-types\"><span class=\"ez-toc-section\" id=\"Non-dynamic_sized_types\"><\/span>Non-dynamic sized types<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>int<\/code>&nbsp;or&nbsp;<code>uint256<\/code>&nbsp;have a default value of&nbsp;<code>0<\/code><\/li><li><code>bool<\/code>&nbsp;have a default value of&nbsp;<code>false<\/code><\/li><li><code>address<\/code>&nbsp;type has a default value of zero address that is&nbsp;<code>0x0000000000000000000000000000000000000000<\/code><\/li><li><code>struct<\/code>&nbsp;type has a default value of all its data members\u2019 default types coupled in a tuple.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dynamic-sized-types\"><span class=\"ez-toc-section\" id=\"Dynamic_sized_types\"><\/span>Dynamic sized types<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Dynamic-sized type variables are the ones that can change their sizes. The sizes of these variables depend on the data they\u2019re assigned. For example, an array can be of length 10 or length 1000.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The&nbsp;<code>string<\/code>&nbsp;type has an empty string default value.<\/li><li>The array\u2019s default value is an empty array.<\/li><li>The&nbsp;<code>byte<\/code>&nbsp;default value is empty or no&nbsp;<code>byte<\/code>.<\/li><\/ul>\n\n\n\n<p>\ud83d\udd25&nbsp;Check this course out:&nbsp;<a href=\"https:\/\/metaschool.so\/courses\/create-your-own-ethereum-token-in-just-30-mins\" target=\"_blank\" rel=\"noreferrer noopener\">Create Your Own Ethereum Token in Just 30 Mins<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"null-in-solidity-conclusion\"><span class=\"ez-toc-section\" id=\"Null_in_Solidity_conclusion\"><\/span>Null in Solidity conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Solidity has this weird feature where it doesn\u2019t support undefined values. In some cases, having the undefined value is beneficial, while in others it is not. In either case, we\u2019ll have to learn to cater to this problem, learn the default values of each type, and then work with them accordingly.<\/p>\n\n\n\n<p><strong>Try it out, ask any question, and let us know how it went by tagging Metaschool on Social Media.<\/strong><\/p>\n\n\n\n<p><strong>Follow us on<\/strong>&nbsp;\u2013<\/p>\n\n\n\n<p>\ud83d\udd2eTwitter \u2013&nbsp;<a href=\"https:\/\/twitter.com\/0xmetaschool\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/twitter.com\/0xmetaschool<\/a><\/p>\n\n\n\n<p>\ud83d\udd17LinkedIn \u2013&nbsp;<a href=\"https:\/\/www.linkedin.com\/company\/0xmetaschool\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.linkedin.com\/company\/0xmetaschool\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":15,"featured_media":7196,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[292],"tags":[51,31,46,29],"class_list":["post-7182","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-answers","tag-blockchain","tag-ethereum-blockchain","tag-solidity","tag-web3"],"_links":{"self":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/7182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/comments?post=7182"}],"version-history":[{"count":3,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/7182\/revisions"}],"predecessor-version":[{"id":7197,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/7182\/revisions\/7197"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/media\/7196"}],"wp:attachment":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/media?parent=7182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/categories?post=7182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/tags?post=7182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}