Learn
Conditional Statements
Comparison Operators
Comparison operators are used to compare values and determine the relationship between them. These operators return a boolean value, either true or false, based on the evaluation of the comparison.
- Equality Operator (==) - checks whether two values are equal. If the values are equal, it returns true; otherwise, it returns false. For example:
- Inequality Operator (!=) - checks whether two values are not equal.
- Greater Than Operator (>) - checks whether the left operand is greater than the right operand.
- Less Than Operator (<) - checks whether the left operand is less than the right operand.
- Greater Than or Equal Operator (>=) - checks whether the left operand is greater than or equal to the right operand.
- Less Than or Equal Operator (<=) - checks whether the left operand is less than or equal to the right operand.
Example:
Instructions
1.
Declare a variable isEqual
and assign it the value of comparing x
and y
using the "equal to" operator.
2.
Print the variable isEqual
to the console.
3.
Declare a variable notEqual
and assign it the value of comparing x
and y
using the "not equal to" operator.
4.
Print the variable notEqual
to the console.
Sign up to start coding
Already have an account?
Sign In
Course content