O'Reilly logo

JavaScript For Kids For Dummies by Eva Holland, Chris Minnick

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 14

Making Decisions with the If…Else Statement

When you need to make an either/or or yes/no decision, the if…else statement is your best friend. In this chapter, you learn how to use if…else statements to create and navigate choices in JavaScript programs.

image

Boolean Logic

In Chapter 9, we talk about JavaScript’s comparison operators and show you how they work in the JavaScript Super-Calculator. Let’s briefly review the comparison operators here.

Equality

The equality operators are == and ===. The difference between the two is that the double equals will convert values between different types. For example, if you compare 3 with "3", the == operator will say that they’re equal, while the triple equals operator will say that they aren’t.

The triple equals operator is called the strict equality operator. We recommend that you always use the strict equality operator in order to avoid bugs.

Not equal

The not equal operators are formed by putting an exclamation point (!) before the equality operators. They tell you whether two values are different. The strict not equal operator (!==) compares values without converting their type and the not equal operator (!=) converts between data types before comparing. We recommend that you always use the strict not equal operator.

Greater than and less than

The greater than (>) and less then (<) operators compare numeric values. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required