{"id":2514,"date":"2022-05-31T19:20:31","date_gmt":"2022-05-31T23:20:31","guid":{"rendered":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/?p=2514"},"modified":"2022-05-31T19:20:31","modified_gmt":"2022-05-31T23:20:31","slug":"what-is-a-variable-in-javascript","status":"publish","type":"post","link":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/2022\/05\/31\/what-is-a-variable-in-javascript\/","title":{"rendered":"What is a variable in JavaScript?"},"content":{"rendered":"<p>A variable in JavaScript is used to a store data value that may be changed later on. It is essentially a name of storage location. There are two types of variables in JavaScript, and those include; local variable and global variable.<\/p>\n<p><strong>Three rules to follow when declaring a JavaScript variable<\/strong>:<\/p>\n<ol>\n<li>Name must start with a letter (a-z or A-Z), underscore( _ ), or dollar( $ ) sign.<\/li>\n<li>After the first letter, use digits (0-9)\u00a0<\/li>\n<li>JavaScript variables are case sensitive (i.e: a and A are different variables because one is lowercase, and the other is uppercase)<\/li>\n<\/ol>\n<p>A <strong>local variable<\/strong> in JavaScript is declared within a block or function, and is only accessible within that function or block.\u00a0<\/p>\n<p>A <strong>global variable<\/strong> in JavaScript is accessible from any function.<\/p>\n<p>You can declare a variable in JavaScript using &#8220;<em>var<\/em>&#8220;, &#8220;<em>const<\/em>&#8220;, or &#8220;<em>let<\/em>&#8220;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2518\" src=\"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/files\/2022\/05\/Screen-Shot-2022-05-31-at-7.19.31-PM-300x183.png\" alt=\"\" width=\"384\" height=\"234\" srcset=\"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/files\/2022\/05\/Screen-Shot-2022-05-31-at-7.19.31-PM-300x183.png 300w, https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/files\/2022\/05\/Screen-Shot-2022-05-31-at-7.19.31-PM-1024x625.png 1024w, https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/files\/2022\/05\/Screen-Shot-2022-05-31-at-7.19.31-PM-768x468.png 768w, https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/files\/2022\/05\/Screen-Shot-2022-05-31-at-7.19.31-PM-1536x937.png 1536w, https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/files\/2022\/05\/Screen-Shot-2022-05-31-at-7.19.31-PM-2048x1249.png 2048w\" sizes=\"auto, (max-width: 384px) 100vw, 384px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A variable in JavaScript is used to a store data value that may be changed later on. It is essentially a name of storage location. There are two types of variables in JavaScript, and those include; local variable and global variable. Three rules to follow when declaring a JavaScript variable: Name must start with a [&hellip;]<\/p>\n","protected":false},"author":28307,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[663943],"tags":[],"class_list":{"0":"post-2514","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-instructor","7":"entry"},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/posts\/2514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/users\/28307"}],"replies":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/comments?post=2514"}],"version-history":[{"count":1,"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/posts\/2514\/revisions"}],"predecessor-version":[{"id":2519,"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/posts\/2514\/revisions\/2519"}],"wp:attachment":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/media?parent=2514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/categories?post=2514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec712summer2022\/wp-json\/wp\/v2\/tags?post=2514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}