Operators
After seeing quite a few data types and some ways to convert them, it is time for the next major building block: operators. These come in handy whenever we want to work with the variables, modify them, perform calculations on them, and compare them. They are called operators because we use them to operate on our variables.
Arithmetic operators
Arithmetic operators can be used to perform operations with numbers. Most of these operations will feel very natural to you because they are the basic mathematics you will have come across earlier in life already.
Addition
Addition in JavaScript is very simple, we have seen it already. We use +
for this operation:
let nr1 = 12;
let nr2 = 14;
let result1 = nr1 + nr2;
However, this operator can also come in very handy for concatenating strings. Note the added space after "Hello"
to ensure the end result contains space characters:
let str1 = "Hello ";
let str2 = "addition";
let...