ItP summary

Literal values

We have learned about five data types. You should be able to read and write literal values of all five types using the appropriate syntax for each type.

  • Numbers: 0, 1, 3.14, -23, -0.456
  • Booleans: true, false
  • Strings: 'the quick brown fox' or "jumps over"

Control constructs

You should be able to use all of the control constructs listed below. You should be able to trace the execution of code using these control constructs and describe when the different parts of the code will be executed.

  • return expression;
  • if (condition) { code }
  • if (condition) { code } else { code }
  • if (condition) { code } else if (condition) { code } else { code }
  • while (condition) { code }
  • for (init; condition; update) { code }

Expressions

You should be able to read and write all of the kinds of expressions listed below as well as understand how to combine expressions into yet more complex expressions using operators, function calls, and method calls.

  • Literal values: 100, 'foo', true
  • Variables: i, color, numberOfCircles
  • Properties: s.length
  • Method calls: s.slice(1), s.toUpperCase()
  • Method chains: s.slice(0, 3).toUpperCase()
  • Function calls: Math.abs(x)
  • With operators: a + b, a ** 2 + b ** 2, s[0]
  • Complex: Math.abs(x1 - x2), s[s.length - 1]

Operators

We have learned about the main operators for each of the three data types as well as equality operators that can be used with any types, comparison operators that can be used with numbers and strings, and grouping parentheses. You should be able to read and write expressions using these operators.

  • Numbers: +, -, *, /, %, **
  • Boolean: &&, ||, !
  • Strings: +, []
  • Comparison (numbers and strings): <, >, <=, >=
  • Equality (all values): ===, !==
  • Grouping: ()

Variables

We have learned how to declare both mutable and immutable variables. You should be able to define your own variables and use variables in expressions to compute values and know how to assign new values to mutable variables.

  • Declaring with let and const
  • Assigning with =
  • As function parameters
  • Increment and decrement operators: ++, --
  • Compound assignment operators: +=, -=, *=, /=, %=, **=

Functions

We have learned how to define functions in both full and shorthand form and the difference between functions that are used to compute values and those that are used for their side effects. You should be able to define your own functions and use function calls, of both your own and pre-existing functions, in expressions and for side effects.

  • Full form syntax: (a, b) => { return a + b; }
  • Defining: const add = (a, b) => { retun a + b; }
  • Calling: add(expression, expression)
  • Returning from functions with return

Properties

We have learned about the length property of strings. You should be able to use these property in expressions to do things like find the last n characters of a string or in a for loop to loop over the characters of a string. And we have learned about the property PI on the special Math object which can be used for in expressions such as Math.PI * r ** 2.

  • Strings: length
  • Math: PI

Methods

We have learned four methods on string values. You should be able to write expressions involving calls to these methods. You should understand and be able to explain the difference between calling slice with one or two arguments and to explain why toUpperCase and toLowerCase do not require arguments. And we have learned the six methods on the special Math object listed below.

  • String: slice, indexOf, toUpperCase, toLowerCase
  • Math: abs, sqrt, floor, random, min, max