{"id":553,"date":"2022-08-30T15:03:16","date_gmt":"2022-08-30T15:03:16","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/how-do-i-stop-getting-this-referenceerror-in-node-js-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:03:16","modified_gmt":"2022-08-30T15:03:16","slug":"how-do-i-stop-getting-this-referenceerror-in-node-js-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-do-i-stop-getting-this-referenceerror-in-node-js-collection-of-common-programming-errors\/","title":{"rendered":"How do I stop getting this ReferenceError in node.js?-Collection of common programming errors"},"content":{"rendered":"<pre><code>    183|             });\n    184| \n &gt;&gt; 185|             \n    186|                 alert(\"Welcome!\");\n    187|             \n    188| \n\njust_registered is not defined\n<\/code><\/pre>\n<p>Basically, I want to say: if just_registered is defined and is true, then alert. However, I want want to set everything to false&#8230;I just want to leave it undefined (i have like 100 variables)<\/p>\n<ol>\n<li>\n<p>Basically your checking whether a local variable exists. To do this you have to use the <code>typeof<\/code> operator since accessing <code>just_registered<\/code> which is an undeclared local variable creates a reference error.<\/p>\n<p>This is best compared to<\/p>\n<pre><code>var foo;\nif (foo) { }\n<\/code><\/pre>\n<p>vs<\/p>\n<pre><code>\/\/var foo;\nif (foo) { } \/\/ ReferenceError\n<\/code><\/pre>\n<p>Where as<\/p>\n<pre><code>\/\/var foo\nif (typeof foo !== \"undefined\") { } \n<\/code><\/pre>\n<p>Will work because accessing an undeclared variable with the typeof operator just returns <code>\"undefined\"<\/code> rather then throwing a <code>ReferenceError<\/code><\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 20:50:49. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>183| }); 184| &gt;&gt; 185| 186| alert(&#8220;Welcome!&#8221;); 187| 188| just_registered is not defined Basically, I want to say: if just_registered is defined and is true, then alert. However, I want want to set everything to false&#8230;I just want to leave it undefined (i have like 100 variables) Basically your checking whether a local variable exists. [&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-553","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/553","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=553"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/553\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}