👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
We first met operators when we were kids learning arithmetic in elementary school. Operators are the symbols between two operands. In web development, we use operators to compare two values ‚Äã‚Äãto determine if an expression is true or false. In this article, we’ll take a look at comparison (also known as relational) and equality operators - these are the two most common types of operators you’ll come across in JavaScript.
There will be times in the creative logic to solve problems where you will need to use comparison or relational operators to conditionally render something to the screen. Let’s take a look at the most common ones you’ll see in your code. Here is the object we will use for the next operators:
- in - use the in operator to see s’ there is a property in your object:
- instanceof - uses the instanceof operator to ask if an is an instance of a constructor class or function.
- Less than (<), Less than or equal to (<=) - A comparison operator that returns true in a conditional statement if operand A is less than operand B. We see this most often when we create a for loop:
- Greater than (>), Greater than or equal to (> =) - A comparison operator that returns true in a conditional statement if operand A is greater than operand B. It is used quite often to try to find the maximum number in an array:
Note: > = does not equal =>. The latter is used for large arrow functions in ES6 JavaScript syntax.