JavaScript greater than or equal to operator

 JavaScript greater than or equal to operator

Doers JavaScript lesson, Section 2. #Doers

JavaScript offers greater than or equal to operator to compare values and return true or false depending on the comparison. 

This operator additionally check if the number is equal before returning the results. In that regards it's a little different than the greater than operator.


Greater than or equal to operator is denoted by the >= symbols. This is part of comparison operators in JavaScript. 

If the number on the left is greater than or equal to the number on the right, it returns true, otherwise it returns false.

Again, Implicit type conversion is performed while using this operator.

<!DOCTYPE html>
<html>
<body>

<button onclick="greaterThanOrEqualTo(5,5)">Check 5 >= 5</button>
<button onclick="greaterThanOrEqualTo(5,15)">Check 5 >= 15</button>
<button onclick="greaterThanOrEqualTo(15,5)">Check 15 >= 5</button>
<p id="result"></p>

<script>
    var x = document.getElementById("result");
function greaterThanOrEqualTo(num1num2) {
    if(num1 >= num2){
        x.innerHTML = true;
    }
    else{
        x.innerHTML = false;
    }    
    }
</script>

</body>
</html>

Post a Comment

0 Comments

React