This forum is now read-only. Please use our new forums! Go to forums
True and False Q
What does it mean when it says var (condition) = true and (condition)=false ?
Answer 538d62379c4e9d0ec6001428
We have the English mathematician, George Boole who gave us a better understanding of binary logic to thank. Boolean logic allows that no data point may contain any more than one of two possible values, be they 0 and 1, a and A, on and off, and so on.
Conditional expressions are boolean in that no matter what is written in the expression, it can only evaluate to true
or false
. Whether there is only one simple assertion or several operands, the end result can only ever be true, or false.
It’s a bit early in your track to go down too many roads, so let’s just review the general meaning of an assertion. An assertion is an expression that may or may not be true. It’s just held out there and evaluated, yielding whatever result, true or false.
1===1
This is an example of an assertion. It’s a flat out expression that says 1 is equal to 1. Browse the Q&A as you go and you will find discussion on the === operator, but now is not quite the time to segue, so I won’t. We’re discussing assertions, nothing more.
var name = "Bill";
if (name==="Bill"){
console.log("This assertion is true");
} else {
console.log("This is not a true assertion.");
}
If we change name
to bill
the assertion will no longer be true. This is the way that conditionals ultimately work. More will unfold itself as you progress. I draw attention to the way the assertion is written inside the conditional expression, and not the way it is written in the opening post.
When we want to assign a conditionally evaluated result to a variable we can use either an if else structure, which you’re just starting to learn, so pay close attention and ask questions (or better, read, read, read, then ask questions) or we can use something that will come up soon, ternary expressions.
var sight = true;
var isBlind = sight ? false : true;
Remember we said the condition could be anything that evaluates to true or false? If the value of a variable is already true
then we go with that. No evaluation necessary. Again, further on in the track you will learn about ‘truthiness’. For now, just ponder conditionals in their simplest form, evaluating simple assertions and quick enough you will have this stuff down.
Answer 55c2f314d3292ffc0c0006c7
Not sure if you’re still around, but thank you Roy for that explanation. It’s people like you and Leng Lee who make this place great.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
9 comments
Thanks Roy!
You’re welcome. Hope it leads you in the right direction.
A little off topic, but do you know how to hide the boolean output when manually changing the value to false? When coding the Dragon slayer game, slaying is declared true, and then at the end of the while loop it is set to false. Whenever I run the program, I see “false” appearing on my output screen. Not causing any problems with the code….just bothersome to me :-)
At the very end of your code, just log something innocuous, like,
console.log('Bye')
. It will prevent that echo.It’s nothing to do with your code, but with the console, itself.
cool, thanks!
George Boole was English. If he was French, his name would have been “Georges” ;-)
Well that only took a year to have pointed out. And that was with a Wikipedia link right beside it the whole time. @PERCE, it would appear you are well on your way to learning how to debug!
lol, thanks
Reading the comments here I’m wondering if I started this course to learn how to write JS or just because of the genius I’ve seen right here in this post :).