Watching:

How to Make the Most of This Programming Course


show more Comparison operators are the main way programming languages compare variables to each other. In this Lynda.com video, Simon covers setting comparison operators to compare number and string values, as well the basic types available in JavaScript for determining if variables are greater, lesser, or equal to each other. show less
please wait ...

Setting comparison operators

So when we're writing if statements and we want to check that one variable is equal to another variable, we use the double equals sign, the equality operator. In this case, if the contents of the variable a are equal to the contents of the variable b, we're going to execute whatever statements are inside the opening and closing curly braces. But there is a mistake that's very easy to make. In fact, pretty much every programmer in a C-based language will make this at sometime in their career, and that's to accidentally use assignment, single equals, instead of equality, the double equals sign or in JavaScript the triple equals sign.

What that means is let's say we create a couple of variables, variable a, set it equal to 5, variable b, set it equal to 10, using the single equals sign to assign to set the values of these variables. A little later on in the code, I might write an if statement, and I'm asking, is a = b? But I accidentally used the single equals sign...

Setting comparison operators
Video duration: 6m 59s 4h 47m Beginner

Viewers:

Comparison operators are the main way programming languages compare variables to each other. In this Lynda.com video, Simon covers setting comparison operators to compare number and string values, as well the basic types available in JavaScript for determining if variables are greater, lesser, or equal to each other.

Subjects:
Developer Web
Author:
please wait ...