{"id":17523,"date":"2016-08-27T22:35:46","date_gmt":"2016-08-27T22:35:46","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=17523"},"modified":"2016-08-27T22:38:45","modified_gmt":"2016-08-27T22:38:45","slug":"computer-science-javascript-null-value-undefined-type-and-value","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/computer-science-javascript-null-value-undefined-type-and-value\/","title":{"rendered":"Computer science:  JavaScript:  null value, undefined type and value"},"content":{"rendered":"<h1>The tutor comments on JavaScript null and undefined.<\/h1>\n<p>Null, it seems, is often mentioned in computer science.  Perhaps it&#8217;s used a little loosely:  it might refer to the value read when there&#8217;s nothing there, or  the value of a variable that doesn&#8217;t exist.<\/p>\n<p>In JavaScript, in my experience:<\/p>\n<ul>\n<li>\nA variable that doesn&#8217;t exist at all is of type <span style=\"font-family:monospace\">undefined<\/span>.  Trying to print its value will prevent the script from running.\n<\/li>\n<li>\nA variable that is declared but not given a value (eg <span style=\"font-family:monospace\">var var1;<\/span>) is also type <span style=\"font-family:monospace\">undefined<\/span>.  However, the program will print its value as <strong>undefined<\/strong>.\n<\/li>\n<li>\nA variable declared with a value <em>null<\/em> (eg <span style=\"font-family:monospace\">var var1 = null;<\/span>) is of type <span style=\"font-family:monospace\">object<\/span>.  Its value will print out <strong>null<\/strong>.<\/p>\n<p>For a possible reason why a variable set as null is of type object, see my post <a href=\"?p=17285\">here<\/a> about Java and  <span style=\"font-family:monospace\">null<\/span>.  JavaScript isn&#8217;t the same as Java, but the two languages may relate to <span style=\"font-family:monospace\">null<\/span> with some similarity.<\/p>\n<p>Source:<\/p>\n<p><a href=\"http:\/\/www.w3schools.com\/js\/js_datatypes.asp\">w3schools.com<\/a><\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor comments on JavaScript null and undefined. Null, it seems, is often mentioned in computer science. Perhaps it&#8217;s used a little loosely: it might refer to the value read when there&#8217;s nothing there, or the value of a variable &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/computer-science-javascript-null-value-undefined-type-and-value\/\"> <span class=\"screen-reader-text\">Computer science:  JavaScript:  null value, undefined type and value<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105,1801,1745],"tags":[1841,1842],"class_list":["post-17523","post","type-post","status-publish","format-standard","hentry","category-computer-science","category-java","category-javascript-computer-science","tag-javascript-null","tag-javascript-undefined"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/17523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=17523"}],"version-history":[{"count":20,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/17523\/revisions"}],"predecessor-version":[{"id":17543,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/17523\/revisions\/17543"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=17523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=17523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=17523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}