{"id":67,"date":"2021-01-28T05:37:19","date_gmt":"2021-01-28T05:37:19","guid":{"rendered":"https:\/\/codecasm.com\/blogs\/?p=67"},"modified":"2021-01-28T05:40:45","modified_gmt":"2021-01-28T05:40:45","slug":"javascript-null-vs-undefined","status":"publish","type":"post","link":"https:\/\/codecasm.com\/blogs\/javascript-null-vs-undefined\/","title":{"rendered":"JavaScript : \u2018null\u2019 vs \u2018undefined\u2019"},"content":{"rendered":"\n<p><strong>Difference between \u2018null\u2019 and \u2018undefined\u2019?<\/strong><\/p>\n\n\n\n<p id=\"800c\">Many of you still think that in JavaScript,&nbsp;<em>null<\/em>&nbsp;and&nbsp;<em>undefined<\/em>&nbsp;are same, but answer is:<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"has-text-align-center wp-block-heading\" id=\"6a4a\"><strong><em>null !== undefined<\/em><\/strong><\/h3>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"cbce\">1. <em>null<\/em><\/h1>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The value&nbsp;<code>null<\/code>&nbsp;represents the intentional absence of any object value. It is one of JavaScript&#8217;s&nbsp;<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/Primitive\" target=\"_blank\" rel=\"noreferrer noopener\">primitive values<\/a>&nbsp;and is treated as&nbsp;<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/Falsy\" target=\"_blank\" rel=\"noreferrer noopener\">falsy<\/a>&nbsp;for boolean operations.<\/p><\/blockquote>\n\n\n\n<p id=\"4651\"><strong>If I say null is an object? Would you believe me? Watch below gif<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"448\" height=\"328\" src=\"https:\/\/i0.wp.com\/codecasm.com\/blogs\/wp-content\/uploads\/2021\/01\/null.gif?resize=448%2C328&#038;ssl=1\" alt=\"\" class=\"wp-image-69\"\/><figcaption>gif demonstrating\u00a0<strong><em>null<\/em><\/strong><br><\/figcaption><\/figure>\n\n\n\n<p id=\"5ed7\">It was surprising to me also, but this the wonderful&nbsp;<strong>JavaScript<\/strong>. We should really understand the working of&nbsp;<strong>JavaScript<\/strong>.<\/p>\n\n\n\n<p id=\"672a\"><strong><em>null<\/em><\/strong>\u00a0means\u00a0<strong><em>empty<\/em><\/strong>\u00a0and can be\u00a0<strong><em>assigned<\/em><\/strong>\u00a0and which means\u00a0<strong><em>nothing<\/em><\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"5715\">2. <strong><em>undefined<\/em><\/strong><\/h1>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The global&nbsp;<code><strong>undefined<\/strong><\/code>&nbsp;property represents the primitive value&nbsp;<code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/Undefined\" target=\"_blank\" rel=\"noreferrer noopener\">undefined<\/a><\/code>. It is one of JavaScript&#8217;s&nbsp;<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/Primitive\" target=\"_blank\" rel=\"noreferrer noopener\">primitive types<\/a>.<\/p><\/blockquote>\n\n\n\n<p id=\"35fc\"><strong><em>No..no..no<\/em><\/strong>, what you are thinking is not like that ?\u00a0<strong><em>undefined<\/em><\/strong>\u00a0is not an object like\u00a0<strong><em>null<\/em><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"448\" height=\"328\" src=\"https:\/\/i0.wp.com\/codecasm.com\/blogs\/wp-content\/uploads\/2021\/01\/undefined.gif?resize=448%2C328&#038;ssl=1\" alt=\"\" class=\"wp-image-71\"\/><figcaption>gif demonstrating\u00a0<strong><em>undefined<\/em><\/strong><br><\/figcaption><\/figure>\n\n\n\n<p><strong><em>undefined<\/em><\/strong>\u00a0means a variable which was declared but not yet been assigned any value.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"187\" src=\"https:\/\/i0.wp.com\/codecasm.com\/blogs\/wp-content\/uploads\/2021\/01\/undefined.png?resize=640%2C187&#038;ssl=1\" alt=\"\" class=\"wp-image-72\" srcset=\"https:\/\/i0.wp.com\/codecasm.com\/blogs\/wp-content\/uploads\/2021\/01\/undefined.png?w=700&amp;ssl=1 700w, https:\/\/i0.wp.com\/codecasm.com\/blogs\/wp-content\/uploads\/2021\/01\/undefined.png?resize=300%2C88&amp;ssl=1 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><figcaption>example for\u00a0<strong><em>undefined<\/em><\/strong><br><\/figcaption><\/figure>\n\n\n\n<p id=\"c58c\"><strong><em>undefined<\/em><\/strong>&nbsp;is of type&nbsp;<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/undefined\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>undefined<\/em><\/strong><\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"1cbb\">Conclusion<\/h1>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong><em>Summary:<\/em><\/strong><\/p><p><strong><em>undefined<\/em><\/strong>&nbsp;is something which is not defined and is of&nbsp;<strong><em>undefined<\/em><\/strong>&nbsp;type<\/p><p><strong><em>null<\/em><\/strong>&nbsp;is empty and having no value and is of&nbsp;<strong><em>object<\/em><\/strong>&nbsp;type<\/p><\/blockquote>\n\n\n\n<p id=\"fdf2\">There are many thing which is still to explore by us in JavaScript. JavaScript really very deep and powerful. Invest your time to learn JavaScript by considering example for each concept you learn.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Difference between \u2018null\u2019 and \u2018undefined\u2019? Many of you still think that in JavaScript,&nbsp;null&nbsp;and&nbsp;undefined&nbsp;are same, but answer is: null !== undefined 1. null The value&nbsp;null&nbsp;represents the intentional absence of any object value. It is one of JavaScript&#8217;s&nbsp;primitive values&nbsp;and is treated as&nbsp;falsy&nbsp;for boolean operations. If I say null is an object? Would you believe me? Watch below [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":68,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[22,4,10],"tags":[9,27,28],"class_list":["post-67","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-javascript","category-ngpune","tag-javascript","tag-null","tag-undefined"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/codecasm.com\/blogs\/wp-content\/uploads\/2021\/01\/maxresdefault.jpg?fit=1280%2C720&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/codecasm.com\/blogs\/wp-json\/wp\/v2\/posts\/67","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codecasm.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codecasm.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codecasm.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codecasm.com\/blogs\/wp-json\/wp\/v2\/comments?post=67"}],"version-history":[{"count":7,"href":"https:\/\/codecasm.com\/blogs\/wp-json\/wp\/v2\/posts\/67\/revisions"}],"predecessor-version":[{"id":78,"href":"https:\/\/codecasm.com\/blogs\/wp-json\/wp\/v2\/posts\/67\/revisions\/78"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codecasm.com\/blogs\/wp-json\/wp\/v2\/media\/68"}],"wp:attachment":[{"href":"https:\/\/codecasm.com\/blogs\/wp-json\/wp\/v2\/media?parent=67"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codecasm.com\/blogs\/wp-json\/wp\/v2\/categories?post=67"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codecasm.com\/blogs\/wp-json\/wp\/v2\/tags?post=67"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}