An operator is a symbol or set of symbols that perform a specific operation like adding, subtracting, comparing, incremining, and assigning values. operators in JavaScript can be classified into 3 types (based on number of operands):
Some operators and their functions
Operator | Operation | Example | Result |
---|---|---|---|
+ |
summation | 10 + 124 |
134 |
* |
multiplication | x* 5 |
multiplies the value of x by 5 |
/ |
multiplication | x/ 5 |
divides the value of x by 5 |
> |
check if greater than | age < 18 |
checks if the value of age is less than 18 |
<= |
check if less or equal | 12 <= 7 |
false |
= |
assign value | x= 5 |
stores 5 on var x |
Loops are used to repeat a code or set of codes without the need to rewrite them, here the syntax of for and while loop:
for loop: for (var i = 0; i < number; i++) { syntax } here you control the number of repitions
while (i < number) { syntax } here the loop will repeat until the conditoin is met