- What is an expression?
An expression can be classified as a number of things, for example: it is a value (whether written or produced) or series of values with an operator applied to them, even a single value with an operator applied to it and they can have expressions within expressions, for example an expression, within parentheses, within an expression ā (5+5)*2 [the (5+5) is an expression as well as the whole equation being an expression].
- What is a binding?
A binding, which is a variable, is a way to store a value. By defining a binding name and assigning it a value, this value can be stored in the computerās memory to be called on throughout the program. Once a binding, or variable, is defined its name can be used as an expression and the value of that expression is the value that is bound to it
- What is an environment?
The environment is basically the current state of the programās bindings and associated values stored in memory at any given time. Even before you allocate values to bindings, the environment is not empty as the language standard contains bindings.
- What is a function?
A function performs an action on a value or expression. It is a piece of the program that is defined by a value - invoking, calling or applying that value (the name of the function) will run that piece of program and output a desired result based on the parameters and arguments of the function.
- Give an example of a function.
function MathProblem(x*y+z)
- What is a side effect?
A side effect is the modification of a value outside of the scope of the function or anything that is input on the screen ā like drawing or writing something. Any function that changes anything, or produces any result, other than what was intended for the function to execute or compute could be classified as a side effect.
- Give an example of a function that produces a side effect and another function that produces a value.
This side effect thing had me a little stumped. I understand I could have gone for the obvious examples and simply returned, for the side effect example, either the prompt function or alert function, but I wanted to understand the whole side effect in terms of local and global variables a little better. To that end, I think the following examples illustrate a function that could result in a side effect but still returns a value and then a function that only returns a value and should have no side effects. If I still have not quite understood this, can someone please let me knowā¦.
Side effect example:
let a = 4;
function incrementalCount() {
return a++;
}
In this value, the variable a is incremented by 1 and changed from a value of 4 to a value of 5, therefore a side effect of changing the value of a variable has occurred.
Return Value example:
function math(a,b) {
let a = 4;
let b = 5;
return a*b;
}
In this example, the variables are defined within the function and will return a value of 20 without changing anything or having any influence outside of the function.
- What is control flow?
Control flow is basically the way the program is read. Assume program coding tells a story, control flow then, is the way the story is told. The story is more like one of those novels that allow you as the reader to make decisions (eg a scary monster jumps out, you can choose to fight the monster or run away ā if you chose to fight, turn to page x, if you choose to run away, turn to page y). So control flow, depending on the commands, tells the program what to do and in what order.
- What is conditional execution?
Conditional execution is where you want the program to do something if one or more conditions are met.
- What kind of keyword do you need to use to invoke conditional execution?
To invoke conditional execution, the keyword āifā is used. Other keywords that can accompany is are āelseā and combining them to form āelse ifā. Switch is another form of conditional execution.