let isTrue = false;
if(!isTrue){
console.log('isTrue')
}else{
console.log(isTrue)
}
Iām thinking the code would actually be something more like this:
let good = perform_some_test_like_authenticate_the_user();
if(good) {
// let the user through
} else {
// stop them, authentication failed
}
In your code itās confusing to test for that variable named isTrue to not be true. I would probably invert it, but I also wouldnāt use a variable named isTrue
. Iād rather use something that matches a sentence like āif good thenā, or āif authenticated thenā. If you write out what you have in English is:
if not true then
Which is kind of hard to mentally parse. There are situations where you want to test for a negative result, but youād use a better variable name in that situation:
let disaster = disaster_test();
if(!disaster) {
// do a good thing
} else {
// recover from disaster
}
I catch it !
I was watch video and he say this -> if(){} statement for -> True and else{} for -> False
and in my code if not true(this what i have in my variable ) then print it. as true statement .
Isnāt it because the value is false (or not true) and the code states to print āisTrueā string not the isTrue variable?
Does it give True
or actually isTrue
?
I had to read your post a couple of times to figure it out.
There should be a āmost incomprehensible postā badge!
not true. print string. my if statement go to variable and ask him what value you have ? my variable response I have false . so my if statement says yes he donāt have true , print as true statement .
Yeah - I couldnāt work why you originally thought false and wondered if the string threw you.
I think JS is odd sometimes, like with truthfulness or more specifically, stating NaN as a number thatās false!?!