Summary as of April 23, 2023
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"
- Arrays:
[]
,[42]
,[1, 2, 'foo']
- Objects:
{ x: 10, y: 20 }
Operators
We have learned about the main operators for each of the three data types as well as comparison operators that can be used with numbers and strings, equality operators that can be used with any types, and grouping parentheses. You should be able to read and write expressions using these operators.
- Numbers:
+
,-
,*
,/
,%
,**
- Boolean:
&&
,||
,!
- Strings:
+
,[]
- Arrays:
[]
- Objects:
[]
- Comparison (numbers and strings):
<
,>
,<=
,>=
- Equality (all values):
===
,!==
- Grouping:
()
We have also learned about the basic assignment operator =
as well as the composite assignment operators like +=
and *=
. You should be able to use assignment operators to
update variables, array elements, and object properties.
- Variable assignment:
x = 10
- Array element assignment:
xs[0] = 10
- Object property assignment:
x.foo = 10
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
andconst
- Assigning with
=
- As function parameters
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.
You should be able to use higher-order functions and methods such
as filter
, map
, and reduce
that
take functions as arguments and how to write recursive functions that
recurse on numbers, strings, arrays, and tree structures.
- Full form syntax:
(a, b) => { return a + b; }
- Shorthand syntax:
(a, b) => a + b
- Defining:
const add = (a, b) => a + b;
- Calling:
add(
expression,
expression)
- Returning from functions with
return
(See control constructs.) - HOF:
anArray.map((n) => n * 2)
- Recursive:
const fib = (n) => n < 2 ? n : fib(n - 2) + fib(n - 1)
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.substring(1)
,s.toUpperCase()
- Method chains:
s.substring(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]
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) {}
if (
condition) {} else {}
if (
condition) {} else if (
condition) {} else {}
while (
condition) {}
for (
init;
condition;
update) {}
Properties
We have learned about one property, the length
property of
both strings and arrays. You should be able to use this property in
expressions to do things like find the last n characters of a
string or in a for
loop to loop over the elements of an
array. You should also be able to write expressions involving arbitrary
properties of objects as well as expressions that create objects with
arbitrary properties.
- Strings:
length
- Number of characters in the string. One greater than the largest valid index. - Arrays:
length
- Number of elements in the array. One greater than the largest valid index. - Objects: arbitrary properties depending on the object
Methods
We have learned four methods on string values. You should be able to write expressions involving calls to these methods.
-
s.substring(start, end)
- Extract a contiguous part of the strings
starting at indexstart
and going up to but not including indexend
. With one argument is equivalent tos.substring(start, s.length)
. s.toUpperCase()
- Return an all uppercase version of the strings
.s.toLowerCase()
- Return an all lowercase version of the strings
.s.indexOf(s2)
- Return the index of the first occurance of the strings2
in the strings
or-1
if it is not present.
We've also learned three methods on arrays.
a.push(value)
- Push the given value onto end of the arraya
.a.pop()
- Pop the last value in the arraya
, removing it from the array and returning it.-
a.slice(start, end)
- Extract a contiguous part of the arraya
starting at indexstart
and going up to but not including indexend
. With one argument, is equivalent toa.slice(start, a.length)
.