Mastering Conditionals

In this section, we'll cover short-circuiting and gain additional practice writing conditionals in JavaScript.

You'll often come across situations where your program needs to make a decision based on whether something is truthy or falsey. We're able to control the flow of our program further by writing compounded conditionals and short-circuit conditionals.

Let's say that you have a user registration page and are working on validation for the sign-up form. Of all of the questions on the form, only two fields are required -- username and password. Our program will have to check to make sure that those two fields are not blank.

Keep in mind that if the username field is filled out, but the password field is left blank, the user should not be able to continue. In this case, we would write a conditional in such a way that only when both fields contain some kind of text, should the user be allowed to continue.

Conditionals are one of our most powerful tools as developers. We've seen the basics. Now it's time to take a look at some more advanced applications of conditionals. After this section, you will be able to combine loops, conditionals, and short-circuit operators to create complex logic in your applications.