A Few More Details About Boolean Expressions

There are just a few more things you need to know about Boolean expressions before you can call yourself a Boolean master. You already know that you can create an if-then statement using code like this:

if (name == "thau") {
  alert("Hello, thau!");
}

This says, "If it is true that the variable name contains the string thau, put up an alert saying Hello, thau! " What you may not know is that you can store the value true or false in a variable and use it later. So, I could have done this instead:

var thisIsThau = (name == "thau");
if (thisIsThau == true) {
  alert("Hello, thau!");
}

The first line tests to see whether the variable name contains the string "thau". If it does, the test is true. This true value ...

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.