1 < 10 || 5 > 10
This example will return TRUE as one of the conditions is met (1 is less than 10). Remember the above statement can be read as such: ‘if 1 is less than 10 or 5 is greater than 10 then return TRUE.’ This allows us to write more flexible queries that apply to more use-cases, making them more reusable, and thus helping us to write fewer lines of code.
All this is great and everything, but you’re probably wondering how we actually use these comparison operators. Well, we can make use of them in conditional statements. What’s a conditional statement? It’s only one of the most important aspects of all programming languages …
Conditional statements allow us to write code that gets executed when certain conditions are met. They enable us to write code that reacts and responds to changes and is dynamic in nature. We are able to do this through the use of four different conditional statements. This is another area of JavaScript where it’s much easier to see it in action, rather than explain. So let’s jump straight in with an example of an if statement.
If statements are quite literally a block of code that will run if a statement is true. The syntax is nice and succinct, and very descriptive.