14: True and False Tests

A common operation in JavaScript is to test an equality of two variables (or values). You might want to know if a variable x is less than, equal to, or greater than another variable y. There are a large number of comparison operations that all fall into the category of "boolean logic", but in programming we'll call this a test. The end result of performing a test is true or false. You perform a test in JavaScript by using a "comparison operator" such as x == y or y != 1. Your computer's CPU even has a TEST instruction that does this.

Equal

In JavaScript, you can test the equality of two variables using == (double equals) or === (triple equals). You can think of == as "could be equal" and === as "definitely equal". You can play with node and try these examples out:

> 1 == '1'
true
> 1 === '1'
false
> '' == 0
true
> '' === 0
false

Learn JavaScript Today

Register today for the Beginner Basics course and get the new releases by just paying the difference. There's also special discounts for existing customers when new courses are released.


Still Not Sure? Check out more curriculum!