{"id":6716,"date":"2017-08-04T04:00:02","date_gmt":"2017-08-04T04:00:02","guid":{"rendered":"https:\/\/assignment.essayshark.com\/blog\/?p=6716"},"modified":"2023-01-04T10:06:32","modified_gmt":"2023-01-04T10:06:32","slug":"javascript-samples-variables-in-javascript","status":"publish","type":"post","link":"https:\/\/assignmentshark.com\/blog\/javascript-samples-variables-in-javascript\/","title":{"rendered":"JavaScript Samples: Variables in JavaScript"},"content":{"rendered":"<blockquote><p><em>Learning a programming language is fun and inspiring, but sometimes it can get challenging. This excitement is probably what inspires people all around the world to give it a try and immerse themselves in the realm of variables, commands and coding. And it\u2019s alright if you don\u2019t feel motivated at times \u2013 learning how to code can get really difficult and frustrating. Knowing this, we started publishing JavaScript samples to help all the struggling students out there. Sometimes a single sentence or a string of code can make you realize what your mistake was and will be a real <a href=\"https:\/\/assignmentshark.com\/javascript-homework-help.html\" target=\"_blank\" rel=\"noopener\">JavaScript homework help<\/a> for you.<\/em><\/p>\n<p><em>We wish to remind you that you are not allowed to use the information presented in our blog without proper references, or to claim the assignment to be your own, since it will be a violation of the copyright law and can profoundly impact your academic future. We can, however, offer you a better option \u2013 your very own JavaScript samples to learn from. Place your order, specify the instructions, pick the expert you liked the most and wait for work to be done. On-time delivery and top-notch quality are guaranteed! You can always check the progress of your order or chat with your expert from your personal page. Programming is difficult, but we know how to make it easy and enjoyable. Now check the sample and decide whether you need further <a href=\"https:\/\/assignmentshark.com\/javascript-homework-help.html\" target=\"_blank\" rel=\"noopener\">JavaScript assignment help<\/a>.<\/em> <!--more--><\/p><\/blockquote>\n<p>Depending on the reason for the creation of your script, you will need to work with the information.<\/p>\n<p>If you are making an Internet shop, you will work with the goods and the basket. If you create the chat, you will have visitors, messages and so on.<\/p>\n<p>To store information, the variables are used.<\/p>\n<p><strong>Variable<\/strong><\/p>\n<p>The variable consists of a name and a dedicated memory which corresponds to it. To declare or, in other words, to create a variable, the keyword \u201cvar\u201d is used:<\/p>\n<p>[code language=&#8221;javascript&#8221;]<br \/>\nvar message;<br \/>\n[\/code]<\/p>\n<p>After the declaration, you can write the data in the variable:<\/p>\n<p>[code language=&#8221;javascript&#8221;]<br \/>\nvar message;<br \/>\nmessage = &#8216;Hello&#8217;; \/\/ save a string in the variable<br \/>\n[\/code]<\/p>\n<p>This data will be stored in the corresponding memory area and available in the future:<\/p>\n<p>[code language=&#8221;javascript&#8221;]<br \/>\nvar message;<br \/>\nmessage = &#8216;Hello!&#8217;;<br \/>\nalert (message); \/\/ Displays the contents of a variable<br \/>\n[\/code]<\/p>\n<p>You can combine the declaration of the variable and writing the data into it:<\/p>\n<p>[code language=&#8221;javascript&#8221;]<br \/>\nvar message = &#8216;Hello!&#8217;;<br \/>\nIt is possible to declare several variables at once:<br \/>\nvar user = &#8216;John&#8217;, age = 25, message = &#8216;Hello&#8217;;<br \/>\n[\/code]<\/p>\n<p><strong>Variable names<\/strong><\/p>\n<p>There are two restrictions for variable names in Javascript:<\/p>\n<ol>\n<li>The name can consist of letters, numbers, symbols, and $ _<\/li>\n<li>The first character must not be a digit.<\/li>\n<\/ol>\n<p>For example:<\/p>\n<p>[code language=&#8221;javascript&#8221;]<br \/>\nvar myName;<br \/>\nvar test123;<br \/>\nSuch symbols as \u201c$\u201d or \u201c_\u201d are considered to be usual, like letters:<br \/>\nvar $ = 1;<br \/>\nvar _ = 2;<\/p>\n<p>alert( $ + _ ); \/\/ 3<br \/>\nAnd such variables will be incorrect:<br \/>\nvar 1a; \/\/ starts with a number<\/p>\n<p>var my-name; \/\/&#8217;-&#8216; is restricted<br \/>\nConstants<br \/>\nA constant is a value that never changes. They are usually called capitalized:<br \/>\nvar COLOR_RED = &quot;#F00&quot;;<br \/>\nvar COLOR_GREEN = &quot;#0F0&quot;;<br \/>\nvar COLOR_BLUE = &quot;#00F&quot;;<br \/>\nvar COLOR_ORANGE = &quot;#FF7F00&quot;;<\/p>\n<p>var color = COLOR_ORANGE;<br \/>\nalert( color ); \/\/ #FF7F00<br \/>\n[\/code]<\/p>\n<p>Technically, the constant is a usual variable and it can be changed. We just agree not to do that.<\/p>\n<ol>\n<li><code>COLOR_ORANGE<\/code> is an understandable name. Using <code>#FF7F00<\/code> is more complicated.<\/li>\n<li>It is much more simple to make a typo in such a string as <code>#FF7F00<\/code>. In <code>COLOR_ORANGE<\/code> it would be easier to notice.<\/li>\n<\/ol>\n<p><strong>Total<\/strong><\/p>\n<p>In JavaScript, you can declare variables to store data. This is done using the var.<\/p>\n<p>Technically, you can simply write the value of the variable and without declaration, but this is not recommended for several reasons.<\/p>\n<p>Variables which are named CAPITALIZED are constants and never change. Usually, they are used for convenience.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learning a programming language is fun and inspiring, but sometimes it can get challenging. This excitement is probably what inspires people all around the world to give it a try and immerse themselves in the realm of variables, commands and coding. And it\u2019s alright if you don\u2019t feel motivated at times \u2013 learning how to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53,35],"tags":[],"class_list":["post-6716","post","type-post","status-publish","format-standard","hentry","category-it","category-samples"],"_links":{"self":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/6716","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/comments?post=6716"}],"version-history":[{"count":10,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/6716\/revisions"}],"predecessor-version":[{"id":13233,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/6716\/revisions\/13233"}],"wp:attachment":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/media?parent=6716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/categories?post=6716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/tags?post=6716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}