JavaScript comparison with less than operator

JavaScript comparison with less than operator

Doers JavaScript lesson, Section 2. #Doers

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



Less than operator is denoted by the < symbol. This is part of comparison operators in JavaScript.

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

Implicit type conversion is performed while using this operator.




<!DOCTYPE html>
<html>
<body>

<button onclick="lessThan(5,10)">Check 5 < 10</button>
<button onclick="lessThan(10,5)">Check 10 < 5</button>
<p id="result"></p>

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

</body>
</html>

Post a Comment

0 Comments

React