In Javascript, a variable is a name of a location that holds data. You use the word let keyword to declare the name you are giving your variable. For example, you would write something like “let MyBook =”. You are now giving your variable a name, the name being MyBook. Now you have to initialize your variable to a value. A value in Javascript is created by assigning it a name. All pieces of data provided in Javascript are considered to be values. Values can be numbers, functions, and, text. Values need to be easily identified and reusable. You can initialize your variable by giving it a value. For example, you would write let MyBook = “I Love Reading”. Now the variable has been given a value. When you run this code, “I Love Reading” is the output. When naming a variable, there are some rules. The variable name must start with either a letter, underscore, or the $ symbol, but they can never start with a number. Once the first character is placed you can incorporate any character you want to finish the name. No spaces are allowed in the name but you are allowed to include anywhere from one to one million characters if you want the name.
There are arithmetic operators in Javascript. These operators allow for certain mathematic actions to be taken when used in the code. Some of the common ones we use are:
addition +
subtraction –
multiplication *
division /
modulus %
When using these arithmetic operators, we have to remember that Javascript uses the PEMDAS rules, which state which part of the equation is to be calculated first. For example in the equation (9*3)+1, the parenthesis would have to be calculated before the 1 is added.
Leave a Reply
You must be logged in to post a comment.