Binding, Functions and Control Flow - Reading Assignment

  1. What is an expression?
    Any fragment of code that produces a value is an expression.
  2. What is a binding?
    A binding occurs when a variable, constant, or let command is given a variable to hold.
  3. What is an environment?
    The environment is the set of binding present in the current coding window.
  4. What is a function?
    Something that can be called, executed, or applied and which is wrapped in a value to show some determinant use case.
  5. Give an example of a function.
    alert(“Welcome to my Webiste!”)
  6. What is a side effect?
    Side effects occur when a function creates a value that changes either the environment in the console, or the internal system workings.
  7. Give an example of a function that produces a side effect and another function that produces a value.
    var num = 5;
    {
    if num >1 = return 1;
    else num <1 = return 0;
    }

func();
8. What is control flow?
The pathway in which a program follows depending on if/else statements.
9. What is conditional execution?
A series of if/else statements put together in combination to create a number of different pathways the program can execute on.
10. What kind of keyword do you need to use to invoke conditional execution?
if/else statements.

  1. An expression is a fragment of code that produces values. It can be literally spelled out or expressed between ()

  2. A binding is is a specific word (let, var, const) that defines an expression that the program can remember for later. It is like a tentacle that reaches out and attaches to a value. It can be moved from one value to another by redefining.

  3. A collection of bindings and their values that exist together = an environment

  4. A function is a pieces of program wrapped in a value. Such values can be applied to run the wrapped program.

  5. The book uses the example prompt(“enter passcode”); creates a dialog box on the screen.

  6. When a program changes the world. Changing something on a screen is an example or a change something within the machine that will effect future statements…

  7. Example of a function that produces a Value = console.log(math.min(2, 4, 6, 8)); it will RETURN the number 2 as the lowest number. Example of a function that produces a side effect = prompt(“enter pass code”); will produce in the side effect of a dialog box pop up asking for a pass code.

  8. When a program contains more than one statement, the statements read from top to bottom as if in a story.

  9. A conditional execution is created in JS by using the word “if”. In these cases, instead of having one straight forward execution, the program will follow one of multiple paths based on direction. Example given: In the most simple of cases, we may want some code executed if and only if a certain condition holds. In the example, the program would only show the value of a number only if a number was entered when prompted. If a word was uses such as parrot, the the expression would not be executed.

  10. If

  1. An expression is where a statement is put together from variables, constants, function or operators and creates a value.
  2. A binding is a declaration of variables into categories/types. It references or maps a variable to a value, an internal state. Such as let, var or int.
  3. An environment is where bindings takes place. This must take place in a certain point in time in order to exist.
  4. A function is a block of code that could take parameters, inputs, and then produce outputs. A function can be reusable and called on recursively.
  5. Example of a function is: private int Function(int x, int y) { int subtraction = x – y; return subtraction;}
  6. A side effect is when expressions or functions are changed (modified) outside its given environment, such as affecting the world by writing text to a screen.
  7. a) Function exampleSideEffect(let word) {console.log(word)} or prompt
    b) Function givenValue(int chosenVal) {return chosenVal*2} or Math.sqrt()
  8. Control flow is the order the code is executed, top-bottom sequentially.
  9. Conditional execution is when the code execution follows conditions, following branches based on conditions.
  10. Conditions: if() {}, else if(){}, or else() {}
  1. A fragment of code that produces a value.
  2. A binding is a feature in JavaScript that allows the user to attach a value to a given name by using the keywords var, let, and const.
  3. The collection of bindings and their values that exist at any given time within a program.
  4. A piece of program wrapped in a value. Often the default environment already has functions available that can be invoked by inputting the name of the binding that holds the function. You can also invoke a function by adding open and closed parentheses after an expression that produces a function value.
  5. prompt(“Are you human?”);
  6. It’s a consequence or additional feature of using a function that may benefit the program aside from any intended value produced.
  7. The alert(); function displays the value given onto the screen, which is a side effect. The function console.log(Math.max(2, 4)); returns the highest value given.
  8. The order in which statements in a program are executed, which is top to bottom.
  9. It is a way to create a condition so that your code is only carried out under the specified criteria using the if keyword.
  10. if/else

• What is an expression?
An expression is a piece of code that produce a value
• What is a binding?
Also called variable, it is used as a place holder (or a reference, a link) for a value or an expression in the environment memory.
• What is an environment?
The environment is the set of variables available at the time of executing a function.
• What is a function?
It is a code block containing a set of instruction to be executed when the binding is called. A function is composed of expressions and is an expression it self.
• Give an example of a function.
function whoAmI (name) {
console.log( “ I am “ + name);
};
• What is a side effect?
Its when function doesn’t directly produce a value. Most of the time it will wait an other input.

Also I would think that :
function that modify the environment are considered side effects. (Correct me if I’m wrong)
• Give an example of a function that produces a side effect and another function that produces a value.
function sideEffect () { prompt(“How was your day?”) };

function value (num, num2) {
console.log(num+num2
}
• What is control flow?
Control flow is related to the other in which expressions great executed. it can be controlled using conditional execution.
• What is conditional execution?
Its a process of adding expression that will execute code only when the condition are met
• What kind of keyword do you need to use to invoke conditional execution?
We use the if and else keyword, they can also be chained. e.g.
if (condition) {
expressions
} else if (condition) {
expressions
} else {

};
Condition keywords also include &&(AND) ||(OR) !(NOT)

  1. What is an expression?
    A fragment of code that produce a value

  2. What is a binding?
    To catch and hold values, also called variable

  3. What is an environment?
    The collection of bindings and their values that exist at a given time is the environment.

  4. What is a function?
    A functions is a piece of program wrapped in a value. Such Values can be applied in order to run the wrapped program.

  5. Give an example of a function.
    Console.log()

  6. What is a side effect?
    If a statement could change the internal state of the machine in a way that will affect the statements that come after it. These changes are side effect.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    Function produces a side effect: alert ()
    Function produces a value: Math.max()

  8. What is control flow?
    The order how the computer executes statements.

  9. What is conditional execution?
    The execute order of statements based on the situation at hand.

  10. What kind of keyword do you need to use to invoke conditional execution?
    If

  1. An expression is a fragment of code that produces a value.

  2. A binding catches and hold values. It can also disconnect from current values and pointed to new ones by using the = operator.

  3. An environment is the collection of bindings and their values that exist at a given time.

  4. A function is a piece of program wrapped in its value. Such values can be applied in order to run the wrapped program.

  5. An example of a function is the little dialogue box that shows in a browser environment asking for user input.

  6. A side effect is a statement that can change something on the screen or change the internal state of the machine in a way that will affect the statements that come after it.

  7. An example of a function that produces a side effect would be :
    var i = 1;
    var j = i++;
    And an example of a function that produces a value would be :
    function let() {
    return 1+2;
    };
    let();
    3

  8. A control flow is when your program includes more than one statement. The statement is executed from top to bottom like a story being read.

  9. A conditional execution is when a program has a branching road and the program takes the proper branch based on the situation.

  10. The keyword if is used to invoke a conditional execution.

  1. What is an expression?
    A fragment of code that produces a value is called an expression
  2. What is a binding?
    A binding is when a meaning has been assigned to something
  3. What is an environment?
    The collection of bindings and their values that exist at a given time is called
    the environment.
  4. What is a function?
    A function is a piece of program wrapped in a value, these can be applied to run the program.
  5. Give an example of a function.
    let luigisDebt = 140;
    luigisDebt = luigisDebt - 35;
    console.log(luigisDebt);
    // → 105
  6. What is a side effect?
    Showing a dialog box or writing text to the screen is a side effect.
  7. Give an example of a function that produces a side effect and another function that produces a value.
    Side effect: Alert (“hello”);
    Value: console.log(Math.max(2, 4));
    // → 4
  8. What is control flow?
    Control flow is the way javascript executes the code. Unless otherwise stated, it will go from top to bottom like the way we read a story. However, there are elements that can be inserted that will affect this flow.
  9. What is conditional execution?
    A conditional execution is an a piece of code that will only be executed if the determined conditions are present. (This is often seen with if statements)
  10. What kind of keyword do you need to use to invoke conditional execution?
    Oh, if statements!

What is an expression?

An expression is any piece of code that returns a value. Every value that is written literally (such as 12 or “Peter”) is an expression.

What is a binding?

A binding is the same thing as a variable. It is used to give a variable a name to use it later. Think of it as a tentacle.

What is an environment?

The environment is the collection of bindings and their values that exist at a given time

What is a function?

A function is a piece of program wrapped in a value.

Give an example of a function.

function avg (a,b)

What is a side effect?

Showing a dialog box or writing text to the screen is a side effect.

Give an example of a function that produces a side effect and another function that produces a value.

Showing a dialog box with ‘alert’ is a side effect.
Using Math.max or Math.min will produce a value

What is control flow?

When your program contains more than one statement, the statements are executed as if they are a story, from top to bottom. Control flow is the order in which our code is executed.

What is conditional execution?

Conditional execution is a function that only executes when the proper condition(s) is/are met.

What kind of keyword do you need to use to invoke conditional execution?

if/else

  1. What is an expression?
    A fragment of code that produces a value is called an expression. Every value that is written literally (such as 22 or “psychoanalysis”) is an expression. An expression between parentheses is also an expression, as is a binary operator applied to two expressions or a unary operator applied to one.

  2. What is a binding?
    To catch and hold values, JavaScript provides a thing called a binding, or variable: let caught = 5 * 5; That’s a second kind of statement. The special word (keyword) let indicates that this sentence is going to define a binding. It is followed by the name of the binding and, if we want to immediately give it a value, by an = operator and an expression.

  3. What is an environment?
    The collection of bindings and their values that exist at a given time is called the environment. When a program starts up, this environment is not empty. It always contains bindings that are part of the language standard, and most of the time, it also has bindings that provide ways to interact with the surrounding system.

  4. What is a function?
    A function is a piece of program wrapped in a value. Such values can be applied in order to run the wrapped program. For example, in a browser environment, the binding prompt holds a function that shows a little dialog box asking for user input. Executing a function is called invoking, calling, or applying it. You can call a function by putting parentheses after an expression that produces a function value.

  5. Give an example of a function.
    For example, in a browser environment, the binding prompt holds a function that shows a little dialog box asking for user input. It is used like this: prompt(“Enter passcode”);

  6. What is a side effect? Showing a dialog box or writing text to the screen is a side effect. A lot of functions are useful because of the side effects they produce. Functions may also produce values, in which case they don’t need to have a side effect to be useful.*

  7. Give an example of a function that produces a side effect and another function that produces a value.
    For example, the function Math.max takes any amount of number arguments and gives back the greatest. console.log(Math.max(2, 4)); // → 4 When a function produces a value, it is said to return that value. Anything that produces a value is an expression in JavaScript, which means function calls can be used within larger expressions. Here a call to Math.min, which is the opposite of Math.max, is used as part of a plus expression:* console.log(Math.min(2, 4) + 100); // → 102

  8. What is control flow?
    The control flow is the order in which the computer executes statements in a script.
    Code is run in order from the first line in the file to the last line, unless the computer runs across the (extremely frequent) structures that change the control flow, such as conditionals and loops.

  9. What is conditional execution? Not all programs are straight roads. We may want to create a branching road, where the program takes the proper branch based on the situation at hand. This is called conditional execution.

  10. What kind of keyword do you need to use to invoke conditional execution?
    Conditional execution is created with the if keyword in JavaScript. In the simple case, we want some code to be executed if, and only if, a certain condition holds. We might, for example, want to show the square of the input only if the input is actually a number.*

  1. What is an expression? A fragment of code that produces a value is called an expression. Every value that is written literally (such as 22 or “psychoanalysis”) is an expression. An expression between parentheses is also an expression, as is a binary operator applied to two expressions or a unary operator applied to one.

  2. What is a binding? How does a program keep an internal state? How does it remember things? We have seen how to produce new values from old values, but this does not change the old values, and the new value has to be immediately used or it will dissipate again. To catch and hold values, JavaScript provides a thing called a binding, or variable: let caught = 5 * 5; That’s a second kind of statement. The special word (keyword) let indicates that this sentence is going to define a binding. It is followed by the name of the binding and, if we want to immediately give it a value, by an = operator and an expression.

  3. What is an environment? The collection of bindings and their values that exist at a given time is called the environment. When a program starts up, this environment is not empty. It always contains bindings that are part of the language standard, and most of the time, it also has bindings that provide ways to interact with the surrounding system.

  4. What is a function? A function is a piece of program wrapped in a value. Such values can be applied in order to run the wrapped program. For example, in a browser environment, the binding prompt holds a function that shows a little dialog box asking for user input. Executing a function is called invoking, calling, or applying it. You can call a function by putting parentheses after an expression that produces a function value.

  5. Give an example of a function. For example, in a browser environment, the binding prompt holds a function that shows a little dialog box asking for user input. It is used like this: prompt(“Enter passcode”);

  6. What is a side effect? Showing a dialog box or writing text to the screen is a side effect. A lot of functions are useful because of the side effects they produce. Functions may also produce values, in which case they don’t need to have a side effect to be useful.

  7. Give an example of a function that produces a side effect and another function that produces a value. For example, the function Math.max takes any amount of number arguments and gives back the greatest. console.log(Math.max(2, 4)); // → 4 When a function produces a value, it is said to return that value. Anything that produces a value is an expression in JavaScript, which means function calls can be used within larger expressions. Here a call to Math.min, which is the opposite of Math.max, is used as part of a plus expression: console.log(Math.min(2, 4) + 100); // → 102

  8. What is control flow? The control flow is the order in which the computer executes statements in a script.

Code is run in order from the first line in the file to the last line, unless the computer runs across the (extremely frequent) structures that change the control flow, such as conditionals and loops.

  1. What is conditional execution? Not all programs are straight roads. We may want to create a branching road, where the program takes the proper branch based on the situation at hand. This is called conditional execution.
  2. What kind of keyword do you need to use to invoke conditional execution? Conditional execution is created with the if keyword in JavaScript. In the simple case, we want some code to be executed if, and only if, a certain condition holds. We might, for example, want to show the square of the input only if the input is actually a number.
  1. What is an expression?
    Some lines of code that resolves to a value.

  2. What is a binding?
    A value or function thats point to value.

  3. What is an environment?
    collection of bindings and their values at that point in time of the programs existence.

  4. What is a function?
    an expression wrapped in a value. It can be executed by calling it

  5. Give an example of a function.

if(x>y){
alert(“x is bigger thay y”);
}
6. What is a side effect?
an observable change in the state of the application

  1. Give an example of a function that produces a side effect and another function that produces a value.
    alert(“show me this side effect”);

  2. What is control flow?
    Functions which will help to take steps in your program.

  3. What is conditional execution?
    A statement which will bring the program in a specific next step.

  4. What kind of keyword do you need to use to invoke conditional execution?
    if, else, or case:

1 - A fragment of code that produces a value is called an expression.
2 - Binding or Variables catches and holds values.
3 - The collection of bindings and their values that exist at a given time is called
the environment.
4 - A piece of program wrapped in a value
5 - prompt(“enter passcode”);
6 - Showing a dialog box or writing text to the screen is a side effect.
7 - console.log(Math.max(2, 4));
// → 4
8 - When your program contains more than one statement, the statements are
executed as if they are a story, from top to bottom.
9 - Not all programs are straight roads. We may, for example, want to create
a branching road, where the program takes the proper branch based on the
situation at hand
10 - If and Else

  1. What is an expression?

A fragment of code that produces a value, in other words it is a combination of variables, operations or values.

  1. What is a binding?

It is a kind of package for data that we want to use in many senarios, can be easily modified, updated and reused.

  1. What is an environment?

Set of bindings that exists at a given time, whether it is our enviroment to write a code or OS on which we are working on.

  1. What is a function?

Set of statements or simply a little piece of program that is used to perform an action.

  1. Give an example of a function.

let number = Number(prompt(“Inser a number”));
function multiplyByFive(number * 5);

Two functions here, Number for converting input given as a string into the number and then own math funtions.

  1. What is a side effect?

In programming it is a situation when statement affects the statements that come after it.

  1. Give an example of a function that produces a side effect and another function that produces a value.

Two functions given in the 5. were good example how side-fx works. The Number function affected the multiplyByFive function, when multiplyByFive gave only a value.

  1. What is control flow?

It is the order in which the program is executing the code, from top to bottom.

  1. What is conditional execution?

When we introduce some conditions into the code, program will not execute it straightforward, but it will execute the code that meets set requirements.

  1. What kind of keyword do you need to use to invoke conditional execution?

if/else if/else

  1. What is an expression?
    A Expression is something that creates value. Can be a Value itself or an operator.

  2. What is a binding?
    A Binding is a variable that replaces a value. You can wire a value to a binding and refer to it later on in the code. It is used mostly to have the opportunity to change the value within the code - which wouldn’t be possible if you would always work with a specific value.

  3. What is an environment?
    Environment is the bindings and their values that a defined to a given specific time.

  4. What is a function?
    A function is a piece of programm merged into a value. The computer knows what step he has to take when the function is called. The Parenthese hold the value the function is working with - it depends on the function what kind of value you have to insert.

  5. Give an example of a function.
    Addieren (a,b):
    let c = a+b;
    return c;

  6. What is a side effect?
    A side effect is a value that is changed when a function is called. You can safe the outcome to work further with it. -> it will influence the next steps.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    a+2= value
    insert name: and the resulting dialog box is the side effect

  8. What is control flow?
    Code ist executed from top to bottom

  9. What is conditional execution?
    There are several ways the programm can execute. It depends on the insert

  10. What kind of keyword do you need to use to invoke conditional execution?
    if
    else

  1. Expression is a piece of code that produces value(1 or 1+1)
  2. Binding is a named reference to a piece of memory that contains a value(let myBinding = ‘Michael’)
  3. A collection of bindings, their names and values that are currently available is an environment
  4. Function is a wrapped piece of code that has name
  5. alert(“HI”), console.log(“my log”)
  6. If function or statement prints something to console or changes outside environment that is a side effect
  7. alert(“Hi”); - produces side effect, a popup with Hi, let myMax = Math.max(10, 20); - returns max value 20
  8. Control flow is an order in which multiple statements and function calls are executed to create a program
  9. Conditional execution is piece of programs where control flow splits and we can choose to execute one flow or another based on logical expressions outputs.
  10. if, else if, else
  1. An expression is a fragment of code that produces a value.

  2. Binding is way to catch and hold values so that you may use them later.

  3. An environment is a collection of variables and values that exist in the memory at the same time.

  4. A function is a piece of program wrapped in a value.

  5. prompt(“enter passcode”); in this case the word prompt is a function

  6. Showing a dialog box or writing text to the screen is a side effect.

  7. let num=0;
    const func = () => {
    num = 1;
    return true;
    }
    func();

  1. Control flow happens when a program contains more than one statement and those different statements act as a story, going in order from top to bottom.

  2. So control flow is like a straight road but conditional execution is branching roads off the main road to essential give output.

  3. The kind of keyword one needs to use to invoke conditional execution is if

  1. An expression is fragment of a code that produces a value.

  2. A binding is a way to access to a stored value, by referring this value to a special reference. So your calling the reference and it will show you the actual value.

  3. An environment is the collection of bindings and their values at the given time.

  4. A function is a piece of program wrapped in a value.

  5. Give an example of a function.
    alert(“Hello World”)

  6. A side effect is a statement which change the program/code which is coming afterwards or change the environment.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    a=7
    b=8
    console.log(c=a+b) -->c=15 value–>side effect c is defined
    console log(c*a)

  8. Control flow is the definition, how the program runs and is executed: Straight from top to bottom.

  9. A conditional execution is a style, where the program is not running on one straight way to the bottom. In some places it has to check the actual value to see, which way it should take.

  10. What kind of keyword do you need to use to invoke conditional execution?

  • if
  • else if
  • else

1 What is an expression?
An expression is where any fragment of code produces a value.

2 What is binding?
A binding also known as a “variable” is used to hold a value in a program for repeat use unlike an expression where the old value is replaced by the new value.

3 What is an environment?
The environment is a collection of bindings and values that exist in a program at any given time.

4 What is a function
Functions are bits of programs wrapped as a function to invoke a program to display a value. For eg. Prompt (“enter your name”) prompt asks you to enter a name…(“enter name”) is the function.

5 Give an example of a function? (the example is in the above question)

6 What is a “side effect”?
Side effects are derived from return values of text displayed on a screen or in a dialogue box.

7 Give an example of a function that produces a side effect and another function that produces a value.
A function that produces a “side effect” would be something like
prompt (“Enter address”)

A function that produces a value would be something like
console.log (math.max(2,4));
=4

8 What is a control flow?
A Control is when the statements in a program are structured in a particular order for execution of the program. (like a story, in orderly fashion)

9 What is conditional execution
Conditional execution are a sort of customized code made up of “IF” and “Else” statements in a program.
for eg. IF number > 5 Then display…
ELSE
display…

10 What kind of keyword do you need to use to invoke conditional execution?
The key word IF is used to invoke a conditional execution.