For this post, we will go over various topics such as comments, assignment operators, and arithmetic operators. As always, open up a repl and code along with this post. You learn more by doing it yourself, and you will build muscle memory. Log all of these operations to the console in your repl and use comments to reinforce what you are doing.
// This is a single-line comment. /* This is a multi-line comment. Everything inside of this comment will not be run. You can also use comments for not only notes, but you can comment out a block of code that you want to leave out but not delete */
Assignment operators assign a value to a variable. You learned about this in previous posts.
const currentLesson = 4; //assignment operator
The addition operator is used for adding numbers, adding booleans, adding variables, and for combining strings together.
// expected result: 4 2 + 2 // expected result: 3 2 + true /* expected result: "I am a Developer" Notice that there had to be a space added at the end of the first string */ 'I am a ' + 'Developer' //expected result: '2001 is my graduation year' 2001 + ' is my graduation year'
The multiplication operator multiplies numbers or numbers stored in variables. Here is an example:
//multiplying numbers 5 * 3 //equals 15 //multiplying variables const number1 = 5; const number2 = 3; const number3 = number1 * number2 // equals 15
- Other operators that can be used to do arithmetic the same way are:
5 - 5 //subtraction| /* exponentiation expected output is 81 same as 3 to the 4th power */ 3 ** 4 1 / 2 //division /*modulus returns the remainder after division */ 12 % 5 ++ // increment (increases a number by 1) -- // decrement (decreases a number by 1)