Reading-Notes

View the Project on GitHub MohammadAl-khatib/Reading-Notes

Expressions and Operators

 

Operators

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):

  1. Uniray operators, in which a single operand (anything with value) is needed to complete the operation like increminting e.g. 1++
  2. Binary operators, here two operands are needed like summation and multiplication and comparison
  3. Ternary operator, JavaScript has only one ternary operator which is the conditional operator i.e. condition ? val1 : val2   Another famous classification for operators is shown in the image below

 

image

 

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

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:

  1. for loop: for (var i = 0; i < number; i++) { syntax } here you control the number of repitions

  2. while (i < number) { syntax } here the loop will repeat until the conditoin is met