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

A free service run by Zed A. Shaw for learncodethehardway.org.