In this video, we're going to talk about Booleans, that is, true and false, and why Booleans matter in terms of programming. So, you may know from the way people talk about computers, sort of colloquially, that computers know about, basically, 0 and 1. On and off, true and false, that sort of one or the other dichotomy. So Boolean is the term that we use to describe what true and false together is. So in JavaScript a Boolean is one of either true or false.
In a sense it's just as simple as that. One thing to note is that, it needs to be spelled exactly like this. All lower case and yeah, spelled correctly in order for JavaScript to know that you mean true and false. If you write true with a capital t, JavaScript is going to think that you mean a variable by that name. Which incidentally, because it's so similar to an existing type, you would really do well to avoid naming any variable true. Likewise all caps that will not work either or any weird combination thereof. None of these will work only all lowercase for both. Now Booleans are important, because they're your way of getting answers from your programs about the state of your program's world. So basically, you can ask questions in the form of, is this true, or is it false? It's one of the few questions that JavaScript can answer for you without you having to do a bunch of extra work. These questions that you can ask JavaScript, and get back the answers that it can give you are generally in the form of comparisons. Which we'll be looking at a little later.
But just to give you a preview, it'll be things like this. So I'll make two variables, I'll say, my first variable will be my location. And we'll assign it to Graz, that's a city in Austria. And we'll make a second variable, my other location, and we'll put in Los Angeles. So now we have two variables, once called My Location and the other called My Other Location. And now I can ask a question of Java Script.
Are these the same? And the way you ask that question is by writing a statement and using three equal signs to tell me are these things exactly the same? And javascript returns false. So, it knows the values of these two variables, and it can tell me whether they are the same. So now, if I change my other location to Graz, like this. And I ask the same question again, I get back true. Now, we are going to look at comparison later as I say. Just note that assignment of a value to a variable is done by with a single equal sign, and then comparisons are done using three, or in some case, is two. So, these are the kinds of questions that we'll be asking of javascript. And without writing any other code, it can give me these answers, and it gives me the answer in the form of a Boolean.
So, that's why these are important. So, that's a look at what Booleans are, there true and false, and how they're important in terms of answering questions in your programs.
Released
11/21/2012- Enabling Firebug and web inspectors
- Using a text editor
- Declaring and assigning a variable
- Booleans and the quest for truth
- Working with objects and arrays
- Using operators and control structures
- Iterating with loops
- Objects, references, and functions
- Understanding variable scope
Skill Level Beginner
Duration
Views
Q: In "How to enable Firebug and web inspectors," at the Chrome Canary part, the author mentions going to the View menu, and then Developer. My Canary has no menu bar. The author uses a Mac, whereas I have Windows. How do I get to the same place?
A: Click the menu button at the top right of Chrome, select More Tools, and then choose Developer Tools.
Share this video
Embed this video
Video: Booleans and the quest for truth