A comparison operator returns a Boolean value indicating that the comparison is true or not. See the following example:
let r1 = 20 > 10; // true let r2 = 20 < 10; // false let r3 = 10 == 10; // true
let a = 10, b = 20; console.log(a >= b); // false console.log(a == 10); // true
This example is straightforward. the variable
a>=b expression returns and
a==10 expression returns
let name1 = 'alice', name2 = 'bob'; let result = name1 < name2; console.log(result); // true console.log(name1 == 'alice'); // true
let f1 = 'apple', f2 = 'Banana'; let result = f2 < f1; console.log(result); // true
In this example,
f2 is less than
f1 because the letter
B has the character code
66 while the letter
a has the character code
To fix this, you must first convert strings into a common format, either lowercase or uppercase and then perform comparison as follows:
let result2 = f2.toLowerCase() < f1.toLowerCase(); console.log(result2); // false
Note that the
toLowerCase() is a method of the String object that converts the string itself to lowercase.
With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...
You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...
We are the best offshore web development company in India providing web applications on Blockchain, AI & Chatbots. 15+ Yrs Exp., Save upto 60% on development.