JavaScript Comparison Operators: In this example, we have shared JavaScript comparison operators with example. Comparison operators Returns true if the operands are equal. Returns true if the operands are not equal. Returns true if the operands are equal and of the same type.
Operator | Sign | Description |
---|---|---|
Equal | == | If both operands are equal, returns true. |
Identical equal | === | If both operands are equal and/or same data type, returns true. |
Not equal | != | If both operands are not equal, returns true. |
Identical not equal | !== | If both operands are not equal and/or same data type, returns true. |
Greater than | > | If left operand larger than right operand, return true. |
Less then | < | If left operand smaller than right operand, return true. |
Greater than, equal | >= | If left operand larger or equal than right operand, return true. |
Less than, equal | <= | If left operand smaller or equal than right operand, return true. |
Example: JavaScript Comparison Operators
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <script> document.writeln(5 == 5); // true document.writeln(5 == '5'); // true document.writeln(5 === '5'); // false type not same document.writeln(5 != 10); // true document.writeln(5 != '10'); // true document.writeln(5 !== '10'); // true document.writeln(5 > 10); // false document.writeln(5 < 10); // true document.writeln(5 >= 5); // true document.writeln(5 <= 5); // true </script> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.