Greater than or equal operator
Your apps will sometimes need to check the relative size of two values, and then possibly perform some specific action using an if, if-else, or while block. < returns true if the value on the left-hand side of the opertor is greater than or equal to the value on the right-hand side of the operator.
Examples
Example: greater than or equal to check
// Basic numeric greater than or equal to check.
var x = 5;
var y = 4;
console.log(x >= 5);
console.log(x >= 6);
console.log(x >= y);
Example: Comparing "apples" to "Apples"
Example: Comparing "apples" to "Apples" Basic string greater than or equal to check. Case matters for string comparison.
// Basic string greater than or equal to check. Case matters for string comparison.
var x = "apples";
var y = "Apples";
console.log(x >= "apples");
console.log(x >= "bananas");
console.log(x >= y);
Syntax
___ >= ___
Parameters
Name | Type | Required? | Description |
---|---|---|---|
___ | any | The operands can be a number/string/boolean, or a variable containing a number/string/boolean, or the number/string/boolean returned by a function, or the number/string/boolean result of the evaluation of an expression. |
Returns
Tips
Tips
- If you want to test if a value is less than, you can use the > operator.
- JavaScript will automatically perform type conversion for you when comparing two values (e.g. the integer 5 will register as equivalent to the string "5").
- When comparing two strings, JavaScript will compare them alphabetically based on character by character comparison left to right. All the upper case letters come before the lower case letters.
- Comparison operators include < <= == > >= !=
Found a bug in the documentation? Let us know at support@code.org.