View on GitHub

reading-notes

https://samahabujwaied.github.io/reading-notes/

Comparison Operators:

Evaluating condition

Operator Description
= (Equal to) is an assignment operator, which sets the variable on the left of the = to the value of the expression that is on its right. This operator assigns lvalue to rvalue.
== (Double equals ) is a comparison operator, which transforms the operands having the same type before comparison.
=== (Triple equals) is a strict equality comparison operator in JavaScript, which returns false for the values which are not of a similar type. This operator performs type casting for equality. If we compare 2 with “2” using ===, then it will return a false value.
!= (Is not equal to) Returns true if the operands are not equal.
!== (Strict not equal to) Returns true if the operands are of the same type but not equal, or are of different type.
> (Greater than to) Returns true if the left operand is greater than the right operand.
< (Less than to) Returns true if the left operand is less than the right operand
>= (Greater than or equal to) Returns true if the left operand is greater than or equal to the right operand.
<= (Less than or equal) Returns true if the left operand is less than or equal to the right operand.

Logical operators

Operator Description
&& (Logical AND ) Returns expr1 if it can be converted to false; otherwise, returns expr2. Thus, when used with Boolean values, && returns true if both operands are true; otherwise, returns false.
|| (Logical OR ) Returns expr1 if it can be converted to true; otherwise, returns expr2. Thus, when used with Boolean values, returns true if either operand is true; if both are false, returns false.
! (Logical NOT ) Returns false if its single operand that can be converted to true; otherwise, returns true.

This table shows the results of the comparison operations

## Loop counters

  1. For loop

The JavaScript for loop statement allows you to create a loop with three optional expressions. The following illustrates the syntax of the for loop statement:

for (initialization; condition; post-expression) { // statements }.

Example: while loop

var i =0; while(i < 5) { console.log(i); i++; }

  1. Do while Loop JavaScript includes another flavour of while loop, that is do-while loop. The do-while loop is similar to while loop the only difference is it evaluates condition expression after the execution of code block. So do-while loop will execute the code block at least once. The following illustrates the syntax of the Do while loop statement: do{ / /code to be executed }while(condition expression)

Example:Do while Loop

var i = 0; do{ alert(i); i++; } while(i < 5)

I HOPE THAT IS CLEAR