Skip to content

Latest commit

 

History

History
46 lines (31 loc) · 957 Bytes

comparators.md

File metadata and controls

46 lines (31 loc) · 957 Bytes

Comparators

Lets now focus on the conditional part:

if (country === "France") {
    ...
}

The conditional part is the country followed by the three equal signs (===). Three equal signs mean that the condition tests if the variable country has the value you test against but also the correct variable (data)type. You can test conditions with double equal signs, too, but that would mean that if(x == 5) would be true for x being 5 and x being “5”. Depending on what your program is doing, this could make quite a difference.

Other conditional test:

  • x > a: is x bigger than a?
  • x < a: is x less than a?
  • x <= a: is x less than or equal to a?
  • x != a: is x not a?
  • x: does x exist?

Add a condition to change the value of a to 10 if x is bigger than 5.

var x = 6;
var a = 0;
var x = 6;
var a = 0;

if (x > 5) {
    a = 10;
}
assert(a == 10);