Expressions and Functions (W1D1) - Learning Objectives

Expressions

  1. Given a working REPL interface, write and execute a statement that will print “hello world” using console.log
console.log("hello world");
  1. Identify that strings are a list of characters defined by using double or single quotes
let validString = "hello";
let anotherValidString = 'hello';
  1. Given an arithmetic expression using +, -, *, /, %, compute its value
Symbol Meaning Example Usage Expected Output
+ Addition 7 + 4 11
- Subtraction 8 - 3 5
* Multiplication 3 * 6 18
/ Division 9 / 3 3
% *Modulo 7 % 5 2
  1. Given an expression, predict if its value is NaN
console.log(undefined + 3); // NaN
console.log("fish" * 2); // NaN
  1. Construct the truth tables for &&, ||, !
A B A && B A || B !A !B
True True True True False False
True False False True False True
False True False True True False
False False False False True True
  1. Given an expression consisting of >, >=, ===, <, <=, compute it’s value
Operator Meaning Example Usage Example Output
> greater than 10 > 4 True
>= greater than or equal to 10 >= (6 + 4) True
=== equal to 10 === (5 + 5) False
< less than 10 < (12 - 2) False
<= less than or equal to 10 <= (12 - 2) True
  1. Apply De Morgan’s law to a boolean expression
  1. Given an expression that utilizes operator precedence, compute its value
  1. Given an expression, use the grouping operator to change it’s evaluation
  1. Given expressions using == and ===, compute their values
console.log(5 === "5"); // false
console.log(5 == "5"); // true
console.log(0 === false); // false
console.log(0 == false); //true
  1. Given a code snippet using postfix ++, postfix –, +=, -=, /=, *=, predict the value of labeled lines
let number = 0;
number++; // equivalent to number = number + 1, currently 1
number--; // equivalent to number = number - 1, currently 0
number += 10; // equivalent to number = number + 10, currently 10
number -= 2; // equivalent to number = number - 2, currently 8
number /= 4; // equivalent to number = number / 4, currently 2
number *= 7; // equivalent to number = number * 7, currently 14
console.log(number); // 14
  1. Create and assign a variable using let to a string, integer, and a boolean. Read its value and print to the console.
let num; // num is currently undefined
num = '5'; // num is given the value of the string '5'
num = 5; // reassigned to an integer is no issue
let sum = num + 4; // sum is assigned a value in the same line it is declared. num is also used in the calculation by simply referencing its name.
console.log(sum); // prints 9 to the console.

Intro to Functions

  1. Define a function using function declaration
  1. Define a function that calculates the average of two numbers, call it, pass in arguments, and print it’s return value
function average(number1, number2) {
  return (number1 + number2) / 2;
}

let score = average (100, 90);
console.log(score); // 95
  1. Identify the difference between parameters vs arguments