{"id":12536,"date":"2020-03-03T12:29:53","date_gmt":"2020-03-03T20:29:53","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=12536"},"modified":"2023-12-01T02:31:16","modified_gmt":"2023-12-01T10:31:16","slug":"javascript-variables","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/javascript-variables\/","title":{"rendered":"JavaScript Variables"},"content":{"rendered":"\n<p>Variables are an integral part of almost every programming language, and are usually one of the first topics you\u2019ll learn when you start coding. Variables can be used to store data in a program, such as strings, numbers, JSON objects, or boolean values.<\/p>\n\n\n\n<p>In JavaScript, there are three different variable types: <code>var<\/code>, <code>let<\/code>, and <code>const<\/code>. Each of these variables have several rules around how they should be used, and have different characteristics.<\/p>\n\n\n\n<p>In this tutorial, we are going to explore the basics of variables in JavaScript. We\u2019ll discuss how to name a JavaScript variable, when you should use <code>var,<\/code> <code>let,<\/code> and <code>const<\/code> variables, and we will explore how hoisting and scope impact variables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">JavaScript Variables<\/h2>\n\n\n\n<p>Variables are used to store data values. For example, a variable may be used to store a user\u2019s email address, or their name. In JavaScript, a variable can contain any types of data, such as a string, a true or false boolean, an object, or a number.<\/p>\n\n\n\n<p>Before the ES6 specification was released, there was one way to declare a variable in JavaScript: var. The <code>var<\/code> keyword can be used to declare a variable that is accessible throughout a program, and can be changed.&nbsp;<\/p>\n\n\n\n<p>Here\u2019s an example of a variable being declared using <code>var<\/code> in JavaScript:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var full_name = \"Alexander Smith\";<\/pre><\/div>\n\n\n\n<p>Our variable can be broken down into a few components:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>var<\/code> is used to declare our variable<\/li>\n\n\n\n<li><code>full_name<\/code> is the name of our variable<\/li>\n\n\n\n<li><code>=<\/code> tells our program that we want to assign a value to our variable (this is called an <code>assignment operator<\/code>)<\/li>\n\n\n\n<li><code>Alexander Smith<\/code> is the value our variable will store<\/li>\n<\/ul>\n\n\n\n<p>Now that we have shown off creating a variable in JavaScript, we can use it in our code. Here\u2019s an example of a JavaScript program that uses our variable:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var fullName = \"Alexander Smith\";\nconsole.log(\"Your name is:\")\nconsole.log(fullName)<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Your name is:\nAlexander Smith<\/pre><\/div>\n\n\n\n<p>To declare a variable that has no value, you can use the <code>var variableName<\/code> code, but without any assignment. Here\u2019s an example of a variable being declared with no value:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var ourExampleVariable;<\/pre><\/div>\n\n\n\n<p>Then, if we want to assign our variable a value, we can use this code: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>ourExampleVariable = \"Example!\"<\/pre><\/div>\n\n\n\n<p>Optionally, we can add <code>var<\/code> to the start of our assignment, like this:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var ourExampleVariable = \"Example!\"<\/pre><\/div>\n\n\n\n<p>Now, if we print <code>ourExampleVariable<\/code> to the console, we get the following response: <code>Example!<\/code><\/p>\n\n\n\n<p>Our variable can store any data type, as we discussed earlier. Here\u2019s an example of a few variables that have been assigned different data types:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var students = [ { name: \"Hannah\", age: 12 }, { name: \"Alex\", age: 13 } ];\nvar name = \"Alexander Smith\";\nvar grade = 82;\nvar passed = true;<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">How to Name JavaScript Variables<\/h2>\n\n\n\n<p>Each programming language has its own rules around how to name variables, and JavaScript is no different. Here are the main rules you should take into account when naming variables in JavaScript:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Variable names can contain numbers, letters, underscores (_), and dollar signs ($)<\/li>\n\n\n\n<li>Variable names cannot contain whitespace characters<\/li>\n\n\n\n<li>Variable names are case sensitive<\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Lexical_grammar#Reserved_keywords_as_of_ECMAScript_2015\" target=\"_blank\" rel=\"noopener\" rel=\"nofollow\">Variable names cannot contain any reserved words or reserved keywords (i.e. <code>break<\/code>, <code>default<\/code>, <code>with<\/code>)<\/a><\/li>\n\n\n\n<li>Variable names should not begin with numbers<\/li>\n<\/ul>\n\n\n\n<p>In addition, JavaScript uses camel case to declare variable names. This refers to writing the first word of a variable in lower case, then capitalizing every future word in the variable. Here\u2019s an example of a variable being declared in camel case:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var fullName = \"Bill Jones\";<\/pre><\/div>\n\n\n\n<p>If we only have one word in our variable, every letter should be in lowercase.<\/p>\n\n\n\n<p>Further, if you declare a variable using the <code>const<\/code> keyword, every letter should be in uppercase.<\/p>\n\n\n\n<p>While this is a lot of information to learn, over time you\u2019ll naturally be able to figure out how your variables should be named. All you need to do is practice!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Var, Let, and Const Variables<\/h2>\n\n\n\n<p>There are three different keywords used to declare a variable in JavaScript. These are: <code>var<\/code>, <code>let<\/code>, and <code>const<\/code>.<\/p>\n\n\n\n<p>Here is a table that breaks down the differences between these three types of variables:<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>Keyword<\/td><td>Variable Scope<\/td><td>Reassign?<\/td><td>Redeclare?<\/td><td>Hoist?<\/td><\/tr><tr><td>var<\/td><td>Function<\/td><td>Yes<\/td><td>Yes<\/td><td>Yes<\/td><\/tr><tr><td>const<\/td><td>Block<\/td><td>Yes<\/td><td>No<\/td><td>No<\/td><\/tr><tr><td>let<\/td><td>Block<\/td><td>No<\/td><td>No<\/td><td>No<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The following are general rules of thumb for using these types of variables:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Use <strong>const<\/strong> as much as possible, <strong>unless you need to redeclare or hoist a variable<\/strong>.&nbsp;<\/li>\n\n\n\n<li>Use <strong>let<\/strong> if you are working with <strong>loops<\/strong>.&nbsp;<\/li>\n\n\n\n<li>Only use <strong>var<\/strong> if:\n<ol class=\"wp-block-list\">\n<li>You are working on <strong>legacy code<\/strong>,&nbsp;<\/li>\n\n\n\n<li>You need a variable that you can redeclare, or<\/li>\n\n\n\n<li>You need a variable accessible <strong>everywhere in the program (i.e., globally)<\/strong>.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\n\n\n<p>If you\u2019re interested in learning more about these variable types, check out our tutorial on how to use the JavaScript <code>let<\/code> variable <a href=\"https:\/\/careerkarma.com\/blog\/javascript-let\">here<\/a>.<\/p>\n\n\n\n<p>This table contains a lot of information, so let\u2019s break down each of the main differences between these variable types: <code>scope<\/code>, <code>reassignment<\/code>, <code>redeclaration<\/code>, and <code>hoisting<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Scope<\/h2>\n\n\n\n<p>Scope is used to refer to where a variable can be accessed within a program. There are two scopes in JavaScript: <code>global scope<\/code>, which is where a variable is declared outside a block of code; and <code>local scope<\/code>, which is where a variable is declared inside a block of code.<\/p>\n\n\n\n<p>Here\u2019s an example of a global variable in JavaScript:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var name = \"Jimmy Peterson\";<\/pre><\/div>\n\n\n\n<p>This variable can be accessed throughout our entire program. So, if we want to access our <code>name<\/code> variable in later functions, we can do so.&nbsp;<\/p>\n\n\n\n<p>Local variables are declared within the scope of a certain block of code. In order to declare a local variable, you should use <code>let<\/code> and <code>const<\/code>, which are given block scope. Here\u2019s an example of <code>let<\/code> being used in a program:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>let day = \"Monday\";\nlet flavor = \"Vanilla\";\nif (day === \"Monday\") {\n\tlet flavor = \"Choc-Chip\";\n\tconsole.log(`It is Monday. Have a scoop of ${flavor} ice cream at lunch.`);\n}\nconsole.log(`It is not Monday. Have a scoop of ${flavor} ice cream at lunch.`);<\/pre><\/div>\n\n\n\n<p>Our code returns the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>It is Monday. Have a scoop of chocolate ice cream at lunch.\nIt is not Monday. Have a scoop of vanilla ice cream at lunch.<\/pre><\/div>\n\n\n\n<p>As you can see, because <code>day<\/code> is equal to <code>Monday<\/code>, our program runs the contents of our <code>if<\/code> statement. So, our program changes the value of the <code>flavor<\/code> variable to <code>Choc-Chip<\/code> and prints out the first message we saw above.<\/p>\n\n\n\n<p>But after the <code>if<\/code> statement has executed, the value of <code>flavor<\/code> returns to <code>Vanilla<\/code>, which was declared in global scope at the start of our program. So, on the final line of code, our program prints out a message asking us to have a scoop of vanilla ice cream, because <code>flavor<\/code> was assigned the value <code>Vanilla<\/code> in global scope.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Redeclaring Variables<\/h2>\n\n\n\n<p>In JavaScript, only <code>var<\/code> variables can be redeclared. This means that you can create a new variable with the same name and keep its value, or assign the variable a different value.&nbsp;<\/p>\n\n\n\n<p>Here\u2019s an example of a program that declares a variable called <code>radioShow<\/code>, then redeclares the variable:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var radioShow = \"KACL\";\nvar radioShow;\nconsole.log(radioShow);<\/pre><\/div>\n\n\n\n<p>Our code returns: <code>KACL<\/code>. In our code, we have declared <code>radioShow<\/code> twice. Although it is not useful in the above example, if we had a longer program, we may want to redeclare a variable. As a result, if we expect to want to redeclare a variable, we should use <code>var<\/code> to declare it. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hoisting Variables<\/h2>\n\n\n\n<p>In JavaScript, a variable can be declared after it has been used, which means that you can use a variable before it has been declared. This behavior is referred to as hoisting.<\/p>\n\n\n\n<p>Let\u2019s use an example to illustrate how hoisting works. Let\u2019s say that we declare a variable called <code>students<\/code> which contains a list of student names, but we declare that variable after we ask our program to print it:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>console.log(students);\nvar students = ['Andy', 'April', 'Donald'];<\/pre><\/div>\n\n\n\n<p>Our program returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>undefined<\/pre><\/div>\n\n\n\n<p>But if we tried to declare our variable without the <code>var<\/code> keyword, our program would return the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Uncaught ReferenceError: students is not defined<\/pre><\/div>\n\n\n\n<p>This shows hoisting in action. Variables can be declared after they are referenced using the <code>var<\/code> keyword. In simple terms, our program interpreted our above example like this:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var students;\nconsole.log(students);\nstudents = ['Andy', 'April', 'Donald'];<\/pre><\/div>\n\n\n\n<p>Unlike variables declared using <code>var<\/code>, <code>let<\/code> and <code>const<\/code> variables cannot be hoisted. Here\u2019s an example of a program that uses <code>let<\/code> to declare a variable: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>let name = \"Graham Rand\";\nfunction exampleFunction() {\n\tif (name === \"Mark Swinton\") {\n\t\tlet name = \"Mark Swinton\";\n\t}\n\tconsole.log(name);\n}\nexampleFunction();<\/pre><\/div>\n\n\n\n<p>When our code runs, the following result will be returned: <code>Graham Rand<\/code>. The <code>let name = Mark Swinton;<\/code> declaration is enclosed within our function, which means that it has local scope. Because we use the <code>let<\/code> keyword, our variable is not hoisted.<\/p>\n\n\n\n<p>In summary, variables using <code>var<\/code> are subject to hoisting, which saves variable declarations in memory. This may result in problems if you define and assign your variables in the wrong order.<\/p>\n\n\n\n<p><code>let<\/code> and <code>const<\/code> variables are not subject to this feature, however, which means that an error will be returned if you try to declare a variable more than once, or reference a variable that has not yet been declared in the relevant scope.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Variables are an important feature of programming and are used to store data values. In this article, we discussed the basics of JavaScript variables, and listed the rules to follow when naming variables.<\/p>\n\n\n\n<p>We also discussed the three main types of variables in JavaScript &#8212; <code>var<\/code>, <code>let<\/code>, and <code>const<\/code> &#8212; and explored how they can be used. Finally, we discussed the role of scope, redeclaring variables, and hoisting in JavaScript variables.<\/p>\n\n\n\n<p>Now you have the knowledge you need to declare and use variables like a JavaScript expert!<\/p>\n","protected":false},"excerpt":{"rendered":"Variables are an integral part of almost every programming language, and are usually one of the first topics you\u2019ll learn when you start coding. Variables can be used to store data in a program, such as strings, numbers, JSON objects, or boolean values. In JavaScript, there are three different variable types: var, let, and const.&hellip;","protected":false},"author":240,"featured_media":12909,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11933],"tags":[],"class_list":{"0":"post-12536","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-javascript"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"JavaScript","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>JavaScript Variables: The Complete Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"JavaScript variables are used to store data in a program. Learn about how variables work in JavaScript, the differences between var, let, and const, and how variable scope and hosting works on Career Karma.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/javascript-variables\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Variables\" \/>\n<meta property=\"og:description\" content=\"JavaScript variables are used to store data in a program. Learn about how variables work in JavaScript, the differences between var, let, and const, and how variable scope and hosting works on Career Karma.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/javascript-variables\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-03T20:29:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T10:31:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/person-in-front-of-laptop-on-brown-wooden-table-2115217.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"667\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"JavaScript Variables\",\"datePublished\":\"2020-03-03T20:29:53+00:00\",\"dateModified\":\"2023-12-01T10:31:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/\"},\"wordCount\":1383,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/person-in-front-of-laptop-on-brown-wooden-table-2115217.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/\",\"name\":\"JavaScript Variables: The Complete Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/person-in-front-of-laptop-on-brown-wooden-table-2115217.jpg\",\"datePublished\":\"2020-03-03T20:29:53+00:00\",\"dateModified\":\"2023-12-01T10:31:16+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"JavaScript variables are used to store data in a program. Learn about how variables work in JavaScript, the differences between var, let, and const, and how variable scope and hosting works on Career Karma.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/person-in-front-of-laptop-on-brown-wooden-table-2115217.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/person-in-front-of-laptop-on-brown-wooden-table-2115217.jpg\",\"width\":1000,\"height\":667},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-variables\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript Variables\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JavaScript Variables: The Complete Guide | Career Karma","description":"JavaScript variables are used to store data in a program. Learn about how variables work in JavaScript, the differences between var, let, and const, and how variable scope and hosting works on Career Karma.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/javascript-variables\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Variables","og_description":"JavaScript variables are used to store data in a program. Learn about how variables work in JavaScript, the differences between var, let, and const, and how variable scope and hosting works on Career Karma.","og_url":"https:\/\/careerkarma.com\/blog\/javascript-variables\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-03-03T20:29:53+00:00","article_modified_time":"2023-12-01T10:31:16+00:00","og_image":[{"width":1000,"height":667,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/person-in-front-of-laptop-on-brown-wooden-table-2115217.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/javascript-variables\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-variables\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"JavaScript Variables","datePublished":"2020-03-03T20:29:53+00:00","dateModified":"2023-12-01T10:31:16+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-variables\/"},"wordCount":1383,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-variables\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/person-in-front-of-laptop-on-brown-wooden-table-2115217.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/javascript-variables\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/javascript-variables\/","url":"https:\/\/careerkarma.com\/blog\/javascript-variables\/","name":"JavaScript Variables: The Complete Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-variables\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-variables\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/person-in-front-of-laptop-on-brown-wooden-table-2115217.jpg","datePublished":"2020-03-03T20:29:53+00:00","dateModified":"2023-12-01T10:31:16+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"JavaScript variables are used to store data in a program. Learn about how variables work in JavaScript, the differences between var, let, and const, and how variable scope and hosting works on Career Karma.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-variables\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/javascript-variables\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/javascript-variables\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/person-in-front-of-laptop-on-brown-wooden-table-2115217.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/person-in-front-of-laptop-on-brown-wooden-table-2115217.jpg","width":1000,"height":667},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/javascript-variables\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/careerkarma.com\/blog\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript Variables"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=12536"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12536\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/12909"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=12536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=12536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=12536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}