{"id":548,"date":"2022-08-30T15:03:11","date_gmt":"2022-08-30T15:03:11","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/default-value-of-a-type-in-javascript-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:03:11","modified_gmt":"2022-08-30T15:03:11","slug":"default-value-of-a-type-in-javascript-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/default-value-of-a-type-in-javascript-collection-of-common-programming-errors\/","title":{"rendered":"Default value of a type in javascript-Collection of common programming errors"},"content":{"rendered":"<p>I don&#8217;t understand why do you ask such a question. Anyways, the default value of a variable in JavaScript is <code>null<\/code> or <code>undefined<\/code>.<\/p>\n<p>For learning purposes, I took this from WikiBooks JavaScript\/Variables and Types:<\/p>\n<blockquote>\n<p>Variables are commonly explicitly declared by the var statement, as shown below:<\/p>\n<pre><code>var c;\n<\/code><\/pre>\n<p>The above variable is created, but has the default value of <code>undefined<\/code>. To be of value, the variable needs to be initialized:<\/p>\n<pre><code>var c = 0;\n<\/code><\/pre>\n<p>After being declared, a variable may be assigned a new value which will replace the old one:<\/p>\n<pre><code>c = 1;\n<\/code><\/pre>\n<p>But make sure to declare a variable with var before (or while) assigning to it; otherwise you will create a &#8220;scope bug.&#8221;<\/p>\n<\/blockquote>\n<p>And now, when you ask why the value is not <code>0<\/code>, it is because, even <code>null<\/code> or <code>undefined<\/code> are values, which are not defined. Not defined is different from being defined and empty. It might return <code>0<\/code>, when the value is declared and not defined.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 20:50:38. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I don&#8217;t understand why do you ask such a question. Anyways, the default value of a variable in JavaScript is null or undefined. For learning purposes, I took this from WikiBooks JavaScript\/Variables and Types: Variables are commonly explicitly declared by the var statement, as shown below: var c; The above variable is created, but has [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-548","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=548"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/548\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}