{"id":388,"date":"2022-08-30T15:00:31","date_gmt":"2022-08-30T15:00:31","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/is-there-a-standard-function-to-check-for-null-undefined-or-blank-variables-in-javascript-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:00:31","modified_gmt":"2022-08-30T15:00:31","slug":"is-there-a-standard-function-to-check-for-null-undefined-or-blank-variables-in-javascript-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/is-there-a-standard-function-to-check-for-null-undefined-or-blank-variables-in-javascript-collection-of-common-programming-errors\/","title":{"rendered":"Is there a standard function to check for null, undefined, or blank variables in JavaScript?-Collection of common programming errors"},"content":{"rendered":"<p>It&#8217;s really about what you need, I use something like:<\/p>\n<pre><code>self.empty = function () {\n    if (\n            element === \"\"          ||\n            element === 0           ||\n            element === \"0\"         ||\n            element === null        ||\n            element === \"NULL\"      ||\n            element === undefined   ||\n            element === false\n        ) {\n        return true;\n    }\n    if (typeof(element) === 'object') {\n        var i = 0;\n        for (key in element) {\n            i++;\n        }\n        if (i === 0) { return true; }\n    }\n    return false;\n}\n<\/code><\/pre>\n<p>But, honestly, that&#8217;s a bit more broad than I would recommend for most, it just happened to evolve based on the integration needs with other people&#8217;s code over time. And, I&#8217;ll even note that it really doesn&#8217;t handle Arrays as well as it should. The best thing to do is give yourself some personal context and make sure you cover it.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 18:41:36. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>It&#8217;s really about what you need, I use something like: self.empty = function () { if ( element === &#8220;&#8221; || element === 0 || element === &#8220;0&#8221; || element === null || element === &#8220;NULL&#8221; || element === undefined || element === false ) { return true; } if (typeof(element) === &#8216;object&#8217;) { var [&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-388","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/388","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=388"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/388\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}