I'm new in Js and i just want to know if my idea of the ! (NOT operator) is right.
e.g
const hasDriversLicense = true;
const hasGoodVision = true;
const isTired = false;
if (hasDriversLicense && hasGoodVision && !isTired) {
console.log("Sarah is able to drive!");
} else {
console.log("Someone else should drive..");
}
in the previous code the condition is that if...
- Sarah has driver's license, and
- if has good vision, and
- is NOT tired
she should be able to drive, okay?
The way I was analyzing this in code was well I have a hasDriversLicense
var which is true
so this means that Sarah actually has a drivers license, and in relation of this way of thinking the next condition also make sense, so hasGoodVision
is true
so it means it has a good vision.
My confusion comes when we are in this part !isTired
, right now the isTired
var is set it to false
that means that if we relate this with our if condition Sarah is able to drive.
So when we say !isTired
that means that isTired
is false
and then becomes true
cause of the !
so this means that actually Sarah is Tired? and she is not able to drive
This way of thinking was confusing but I start thinking that the !
works as a validator not really as a value changer of the complete context. What I mean with this is that we can say that this !isTired
is like saying "validate if this var value is actually false in that case return true", so it's true that is false
that's why we get this. Is this a valid way see the behavior of this operator?
want to know if my idea of the ! (NOT operator) is right.