**Operators in depth**
some examples of logical operators.
1. Additional operators
Logical AND operator: &&
Logical OR operator: ||
Logical NOT operator: !
The modulus operator: %
The equality operator: ==
The strict equality operator: ===
The inequality operator: !=
The strict inequality operator: !==
The addition assignment operator: +=
The concatenation assignment operator: += (it's the same as the previous one - more on that later)
The logical AND operator in JavaScript: &&
The logical AND operator is, for example, used to confirm if multiple comparisons will return true.
In JavaScript, this operator consists of two ampersand symbols together: &&.
Let's say you're tasked with coming up with some code that will check if the currentTime variable is between 9 a.m. and 5 p.m. The code needs to console.log true if currentTime > 9 and if currentTime < 17.
var currentTime = 10;
console.log(currentTime > 9 && currentTime < 17);
How does this code work?
First, on line one, I set the currentTime variable, and assign the value of 10 to it.
Next, on line two I console log two comparisons:
currentTime > 9
currentTime < 17
I also use the && logical operator to join the two comparisons.
Effectively, my code is interpreted as the following:
1
console.log(10 > 9 && 10 < 17);
The comparison of 10 > 9 will return true.
Also, the comparison of 10 < 17 will return true.
This means I can further re-write line two of my solution as follows:
1
console.log(true && true);
In essence, this is how my code works.
Now, the question is, what will be the result of console.log(true && true)?
To understand the answer, you need to know the behavior of the && logical operator.
The && logical operator returns a single value: the boolean true or false, based on the following rules:
It returns true if both the values on its right and on its left are evaluated to true
It returns false in all the other instances
In other words:
console.log(true && true) will output: true
console.log(true && false) will output: false
console.log(false && true) will output: false
console.log(false && false) will output: false