No ratings yet.

Javascript comparison operators

 

 

 

 

 

 

 

 

 

 

JavaScript Comparison Operators Operator

Description Usage == Equal operator returns true if the operands are equal. true == true; “truth” == “truth”;

!= Not equal operator returns true if the operands are not equal. true != false; “7” != 7;

=== Strict equals returns true if the operands are equal and the same type. 7 === 7;

!== Strict not equals returns true if the operands are not equal and/or not of the same data type. “7” !== 7;

> Greater than returns true if the left operand is greater than the right operand. 7 > 3;

< Less than returns true if the left operand is less than the right operand. 3 < 7;

>= Greater than or equal returns true if the left operator is greater than or equal to the right operator. 7 >= 7;10 >= 7;

<= Less than or equal to returns true if the left operand is less than or equal to the right operand. 3 <= 3; 3 <= 7;

 

Arithmetic JavaScript Operators Operator Descriptio

++ Increment operator adds one (1) to the operand. This works for prefix (++x) to add one and then return the value of x, and postfix (x++) to return the value before incrementing its value.

— Decrement operator subtracts one (1) from the operand. Like the increment operator, it works on operators in both the prefix (return the value after decrements) and postfix (return the value before decrement).

– This operator holds a different meaning if it is a prefix of a numeric operator. Although 3 – 1 returns 2, if you prefix a variable with the negative operator, it multiplies the number by –1, giving you the operand’s (the variable) negation (the number multiplied by –1).

% The modulus operator returns the remainder of the division of two operands. For example, 7 % 2 returns 1(e.g., 7/3 = 2 with a remainder of 1).

Please rate this