Project Falcon
Operating and Expressing!
If variable a holds 10 and variable b holds 15, then:
| Operator | Operation | Description | Expression | Result |
| -------- | ------------------- | -------------------------------------------- | ---------- | ------ |
| + | addition | adds two operands | a + b | 25 |
| - | subtraction | subtracts second operand from the first | a - b | -5 |
| * | multiplication | multiplies the operands | a * b | 150 |
| / | division | divides first operand by second operand | b / a | 1 |
| % | modulus (remainder) | returns the remainder after integer division | b % a | 5 |
If variable a holds the value 42, then:
| Operator | Operation | Description | Expression | Equivalent to... | a's value afterwards |
| -------- | --------- | ---------------------------------------------------- | ---------- | ---------------- | ---------------------- |
| ++ | increment | adds one to the value its int operand holds | a++ | a = a + 1 | 43 |
| ‐‐ | decrement | subtracts one from the value its int operand holds | a-- | a = a - 1 | 41 |
If variable a holds 10, then:
| Operator | Operation | Description | Expression | Result |
| -------- | --------- | ------------------------------------------ | ---------- | ------ |
| == | equal to | evaluates true if the two values are equal | a == 10 | |
a == '10'
a == 11
a == '11' | true
true
false
false != | not equal to | evaluates true if the two values are not equal | a != 10
a != '10'
a != 11
a != '11' | false
false
true
true
If variable a holds 10, then:
| Operator | Operation | Description | Expression | Result |
| ------------ | --------------- | -------------------------------------------------------- | ---------- | ------ |
| == | strict equal to | evaluates true if the two values and types are equal | a === 10 | |
| a === '10' | true | | | |
false != | strict not equal to | evaluates true if the two values and types are not equal | a !== 10
a !== '10' | false
true
If variable a holds 10 and variable b holds 15, then:
| Operator | Operation | Description | Expression | Result |
| --------- | ------------------------ | --------------------------------------------------------------------------------------- | ---------- | ------ |
| > | greater than | evaluates to true of the first operand is greater than the second operand | a > b | false |
| >= | greater than or equal to | evaluates to true of the first operand is greater than or equal to the second operand | a >= b | |
| a >= 10 | false | | | |
true < | less than | evaluates to true of the first operand is less than the second operand | a < b | true <= | less than or equal to | evaluates to true of the first operand is less than or equal to the second operand | a <= b
a <= 10 | true
true
If variable a holds true and variable b holds false, then:
| Operator | Operation | Description | Expression | Result |
| ----------------------------- | --------------- | -------------------------------------------- | ---------- | ------ |
| && | conditional AND | evaluates to true if both operands are true; | | |
| otherwise, evaluates to false | a && b | | | |
| a && true | false | | | |
true || | conditional OR | evaluates to true if either operand is true;
otherwise, evaluates to false | a | | b
b | | false | true
false
Let's translate English statements into JavaScript. First, we'll do one together.
Start by writing the statements as comments. Here's an example:
// Jessica is 23 years old. const jessicaAge = 23; // Sam is 47. const samAge = 47; // Jessica is younger than Sam. console.log(jessicaAge < samAge);
The word "is" means equals. How do we represent assignment?
// Jessica is 23 years old.
If Jessica "is 23", then Jessica's age = 23:
const jessicaAge = 23;
To say Jessica is younger than Sam means we are comparing their ages. Which operator would we use to compare them?
// Jessica is younger than Sam.
We use the "less than" relational operator to perform this comparison:
console.log(jessicaAge < samAge);
The statement:
const jessicaAge = 23;
reads as "Jessica's age is 23."
log is a method, so it ends with a set of opening and closing parentheses:
console.log(jessicaAge < samAge);
Inside the parentheses, we find the method arguments. For the log method, this is what we want to print. In this case, that's whether Jessica is younger than Sam.