- What is an expression?
A piece of code that produces a value.
- What is a binding?
A binding or variable is a construct that has been assigned a value, i.e. it holds the assigned value. Bindings can hold different values if they are assigned to different values throughout the code but there are also constant bindings that hold the same value as long as the binding exists.
- What is an environment?
The environment describes the collection of bindings and their values that exist at a given time.
- What is a function?
A function is a piece of code that takes in arguments and generates value/output based on these arguments. A function needs to be defined once and then can be invoked over and over again. Usually, the range of valid arguments for a function is limited (e.g. only numerical values).
- Give an example of a function?
The following function takes in two numerical values as arguments and returns the sum of both arguments as output:
function numsum(num1, num2) {
return num1 + num2;
}
- What is a side effect?
A side effect is any effect caused by a function that affects something outside the function’s boundaries. Printing something on the screen or opening a dialogue box would be a side effect (effect is not within the boundaries of the function).
- Give an example of a function that produces a side effect and another function that produces a value.
Function producing a value (see answer #5): numsum(2, 8);
This function returns the numerical value 10 (no side effect).
Function producing a side effect: console.log(numsum(2, 8));
This function prints 10 on the screen, which is a side effect, and returns undefined.
Question: From the examples provided in the book Eloquent JavaScript on p. 27 I understand that the author says that the following function returns a value: console.log(Math.max(2, 4))
Technically speaking, isn’t it the case that this function only prints the value and returns undefined? Or am I misinterpreting something?
- What is control flow?
Control flow is the order in which the code is executed.
- What is a conditional execution?
A particular piece of code is executed if, and only if, a certain condition holds. In case the condition doesn’t hold, the code is not executed or an alternative code is executed instead.
- What kind of keyword do you need to use to invoke conditional execution?
The keyword for conditional execution is “if”. However, while-, do- and for-loops also run only as long as the underlying condition is true (the boolean value of the condition must be true).