Why give true not false?

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
}
1 Like

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?

1 Like

I had to read your post a couple of times to figure it out. :smile:

1 Like

There should be a ā€˜most incomprehensible postā€™ badge! :joy:

1 Like

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 .:sweat_smile:

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!?!