From the course: Computer Science Principles Lab: JavaScript

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Build compound conditional tests

Build compound conditional tests - JavaScript Tutorial

From the course: Computer Science Principles Lab: JavaScript

Start my 1-month free trial

Build compound conditional tests

- [Instructor] In JavaScript, logic operators like and and or are used to combine multiple equality evaluations together to create compound conditional tests. In JavaScript, the or operator is a double pipe, which is the Shift + Backslash key on the keyboard. We can create a simple or test using literal boolean values. In our JavaScript file, create a new if statement. We're going to ask if true or false is true. We'll create a new code block, and we'll access the console log and post a message. Only one value needs to be true in an or statement for the whole evaluation to be true. In this example we have a literal true and false that are being tested using the or operator. Since only one of them needs to be true, the entire evaluation is evaluated as true. Save and load in the browser. We can see in the console output that the message is displayed. For an and test we use the double ampersand. If true and false, then we'll put in another console log message. But, since we know that…

Contents