Binding, Functions and Control Flow - Reading Assignment

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

2. What is a binding?
Bindings are used to catch and hold values in JS.

3. What is an environment?
A 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.

5. Give an example of a function.
The binding prompt holds a function that shows a little dialog box asking for user input.

6. What is a side effect?
A side effect is any application state change that is observable outside the called function other than its return value.

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

  • PROMPT function produces a side effect.
  • SUM function produces a value.

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

9. What is conditional execution?
When we create a branching road, where the program takes the proper branch based on the situation at hand it is called conditional execution.

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

The if keyword.

1 Like
Questions

1.[spoiler] A fragment of code that produces a value.[/spoiler]
2. [spoiler]Also known as variable, a binding is something that allows to grasp/point to a value.[/spoiler]
3. [spoiler]It’s a collection of bindings and their values that exist at a given time, which provide ways to interact with the surrounding system.[/spoiler]
4. [spoiler]It’s a piece of program wrapped in as a value, which can take or not arguments.[/spoiler]
5.[spoiler] prompt("Enter password"); [/spoiler]
6. [spoiler]Showing a dialog box or writing text to the screen.[/spoiler]
7.
[spoiler]

Side Effect: prompt("Enter passcode”);
producing a value: console.log(Math.max(2, 4));

[/spoiler]
.
8. [spoiler]It is the order by which statements are executed.[/spoiler]
9. [spoiler]It refers to a command that is only executed if a certain condition is true.[/spoiler]
10. [spoiler]if, else if, else[/spoiler]

1 Like
  1. An expression is a piece of code that returns a value.
  2. Binding is to give an element a value which is stored in it
  3. Collection of bindings and their values at any given point of time
  4. It’s a named piece of program that executes a specific task
  5. console.log(2+2)
    // 4
  6. A change that affects the internal state of the machine in a way that will affect the statements that come after it.
  7. promp(“Your Name”)
    console.log(2+2)
  8. Executing the statements from top to bottom in sequence.
  9. Branching the control flow of a program based on whether specific conditions are met or not.
  10. if, else
1 Like

Nice answers. Good job! :+1:

love it… as always

Ivo

1 Like
  1. What is an expression? A fragment of code that produces a value and can contain a sequence of values, operators and subsets of expressions.

  2. What is a binding? Bindings grasp or connect values and are used to hold values together. The keyword let , indicates the sentence is going to define a binding. i.e.

let b = 5

console.log (b * 5);

// —> 25

  1. What is an environment? An environment is a collection of bindings and their values that exist in any point in time and always contains bindings that are part of the language standard, sometimes interacting with the surrounding environment.
  2. What is a function? A function is a piece of program wrapped in a value, values can then be applied to run the wrapped value.
  3. Give an example of a function. The little dialog prompt in a browser that asks for asking for user input. i.e. (“Enter passcode”);
  4. What is a side effect? Return values showing a dialogue box or text writing to the screen is a side effect.
  5. Give an example of a function that produces a side effect and another function that produces a value. side effect : console.log (Math.max(2, 4)); // —> 4 function that produces a value: console.log (Math.min(2, 4) + 100); // —> 102
  6. What is control flow? Control Flow is about the order of execution when your program contains more than one statement.
  7. What is conditional execution? When a particular branch is taken depending on the situation at hand giving more than one path of execution.
  8. What kind of keyword do you need to use to invoke conditional execution?
    This is denoted by the word; if, else.
1 Like
1. What is an expression?
An expression is a fragment of code that produces a value.

2. What is a binding?
A binding or variable is used to catch and hold values. Bindings do not contain values, they grasp them.

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

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.

5. Give an example of a function.
prompt("Enter passcode");

6. What is a side effect?
A side effect is the result of showing a dialog box or writing text to the screen.

7. Give an example of a function that produces a side effect and another function that produces a value.
alert("Hello");
console.log(Math.max(2, 4));

8. What is a control flow?
When a program contains more than one statement, the control flow dictates that the statements are executed as if they are a story, from top to bottom.

9. What is conditional execution?
A conditional execution is when instead of a straight road there is a branching road, where the program takes the proper branch based on the situation at hand.

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

The if keyword is used in JS to invoke a conditional execution.

1 Like
  1. What is an expression?
    It is any bit of code, even something a small - for example just writing a number.

  2. What is a binding?
    It is like a ‘placeholder’ for variables, but not permanent. The value or expression bound to the binding can be changed at any point in the program. It can be any word (apart from the javascript defined keywords, and cannot begin with a number)

  3. What is an environment?
    A collection of bindings and their values

  4. What is a function?
    A function is a program that is linked or wrapped to binding will execute when invoked

  5. Give an example of a function.
    The binding “prompt” is a invokes a function, it displays a pop up box requesting input from the user.

  6. What is a side effect?
    If a statement or function has an affect on real world or requires real world action like user input it is considered a side effect.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    “prompt” produces a side effect of a popup entry box
    “console.log” produces a side effect of a value, something written to the screen.

  8. What is control flow?
    It is the order in which the program executes.

  9. What is conditional execution?
    This is when the program follows one of several branches dependent on some conditional test.

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

1 Like
  1. A fragment of code that produces a value.
  2. It’s a keyword that catch and hold a value in my program. I can change the value anytime I want in the program. Muliples bidings can also be equal to themselves.
  3. The collection of bindings and their values that exist at a given time.
  4. A function is a piece of program wrapped in a value.
  5. Math.min(5, 7);
    It will give the result of 5.
  6. It is any application state change that is observable outside the called function other than its
    return value.
  7. Function that produces a side effect: prompt(‘hello’);
    Funtion that produces a value: Math.max(1, 5) + 10;
  8. When a program contains more than one statement. The statement are executed from top to
    bottom.
  9. Conditional statements are used to decide the flow of execution based on different
    conditions. If a condition is true, you can perform one action and if the condition is false, you can
    perform another action.
  10. if and else
1 Like

What is an expression?
Anything written in java ending with a semicolon and creates a value can be called an expression.

What is a binding?
Binding is a set of rules that gets binded with an “equal sign”

What is an environment?
Its a collection of bindings and their values. Some of them are included in a program at startup
while others are user defined.

What is a function?
Its a piece of program wrapped in a value. If a function is envoked eg. “prompt”
then the webbrowser can ask the user input as password.

Give an example of a function.
promt = password

What is a side effect?
Its the effect that something like a prompt can cause in a onscreen display, like password

Give an example of a function that produces a side effect and another function that produces a value.
prompt = “enter password” (side effect)
let promt = 5*5 (value)

What is control flow?
Its the direction whereto the program is directed, straight,forks,loops, dead ends ,left side of circle etc

What is conditional execution?
The flow of a program can only continue if conditions are met.

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

1 Like

1.Code that produces value is called expression.
2. Binding is variable that stores value
exa: let a =5; here let defines a bidding
3.The collection of bindinds and their values that exist is Environment .
4.A function is code that performs specific task
5.prompt(“Enter your password”)
6.Showing a dialog box or writing text to the screen -result that changes something that affects the program
7.
-side effect example:
prompt(“Enter your password”)
-value example:
console.log(Math.max(4,6,8));
the output value will be 8
8.Control flow is order or program - when the statements are executed from top to bottom.
9.Conditional execution means - that code will be executed only IF certain condition is fulfiled (true or false )
10.We use keyword if and else

1 Like
  • What is an expression?
    A fragment of code that produces value is called an expression

  • What is a binding?
    The special word (keyword) let indicates that this sentence is going to define a binding

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

  • What is a function?
    A function is a piece of program wrapped in a value

  • 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”);

  • 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
    An example of an side effect the function Math.max takes any amount of number arguments and gives back the greatest.
    console.log(Math.max(2, 4)); // → 4
    An example of another function that produce a value is 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

  • 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 is called a control flow.

  • What is conditional execution?
    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. This is called conditional execution.

  • What kind of keyword do you need to use to invoke conditional execution?
    alert, if

1 Like
  1. An expression is a fragment of code that produces a value. The value can be a number and a string.

  2. A Binding is a value that is stored so it can be used later. console.log(1 + 1); // -> 2 the 2 is kept for later.

  3. The collection of bindings and their value that exist at a given time is called the environment.

  4. A function is a code that after being executed gives an output.

  5. console.log("Hello World");

  6. A side effect is when a dialog box or text is shown on the screen.

  7. Produces a side effect: prompt(" "); this has the side effect of showing a dialog box.
    Produces a value: console.log(Math.max(4, 7) + 50); // -> 57

  8. It means that the program reads your command from top to bottom.

  9. A conditional execution is when the program can decide which road can be chosen. It chooses the road that fits best at the moment and it executes a code only if a certain condition has been met.

  10. if, else if and else

1 Like
  • What is an expression?
    An expression is a section code that produces a value.
  • What is a binding?
    A binding or variable is used to hold a value so you can use later. By using a keyword such as ‘let’ you can define a binding which you can then name.
  • What is an environment?
    The environment is the collection of bindings and their values in a program that exist at that time.
  • What is a function?
    A function is a section of code wrapped in a value to carry out a task which can then be executed by applying or calling it.
  • Give an example of a function.
    console.log ( ) or prompt ( )
  • What is a side effect?
    Functions can be useful because of side effects they produce such as showing a dialog or writing text to screen.
  • Give an example of a function that produces a side effect and another function that produces a value.
    console.log produces a side effect
    Let produces a value
  • What is control flow?
    It is the order in which more than one statement in the program will be carried out.
  • What is conditional execution?
    You may want the program to take a different branch depending on the situation and the conditional execution allows it to do so.
  • What kind of keyword do you need to use to invoke conditional execution?
    If or else
1 Like
  1. A fragment of code that produces a value.

  2. Catches and hold values,

  3. Collection of bindings and their values that exist at a given time

  4. Is a piece of program wrapped in a value.

  5. Enter password

  6. Amounts to something only if it affects the world. It could display something on the screen that contents are changing.

  7. Let x=10;
    Not sure bout fucntion that procedures a value

  8. When a program contains more then one statement it is executed as a a story from top to bottom

  9. Not all programs are straight line roads. For example want to create a branching load where the proper branch based on the situation at hand

  10. Let, var, else, if

Here is a simple example to how a function can produce a value:
Lets say you want to do a simple math operation function to Add two numbers:

First we create two variables and bind a value to each:

var x= 10;
var y= 20;

Second we create a function structure that will to the math operation “Add”:

function operator_Add(number1, number2){
 var result = 0;
 result = number1 + number2;
 return result;
}

Finally we invoke or call the function like this with the two variables created at the beginning:

var finalResult = operator_Add(x, y);

The result of the function will return the addition of both variables inserted in the function, so the result will be 30, the result is the side effect of the function that will be used for the variable “finalResult”.

Hope this give you an idea of how functions works. Let me know if there is still any doubt to redesign this example!

@Fabrice
Carlos Z.

2 Likes
  1. An expression is a fragmnt of code that produces a value (e.g. 2 * 3 is an expression that produces the value 6). Also every value that can be written literally is also an expression (e.g. a string such as “this is a string”). An expression can also contain other expressions (e.g. (2 * 3) + ( 4 * 5), which evaluates to 6 + 20, which then evalutes to the resulting value of 26).

  2. A binding points to a value. Its another term for a variable. A binding is given a name (consisting of alphabetic characters, numbers and/or the symbols $ and _ , providing the name chosen isn’t a Javascript keyword). Once it is given a name it can be pointed to any value (a specific number, string or boolean value) and used to represent that specific value in expressions.

  3. The environment consists of all the bindings and their values that exist at the current time. Note: Even when the program starts up there are already language specific bindings present and so the environment is never empty.

  4. A function is a piece of code that is passed a number of arguments and returns a value. The function can be called from elsewhere in the program, passing it the specific values (as the arguments) for it to use this time in its execution, with the result being returned to where the program was called from in the program.
    The language defined functions are many of the values in the environment. A function in this sense is a piece of code wrapped up in a value. In the environment when the specific value is applied the function is executed.

  5. An example function (with is an inbuilt Javascript function) is: prompt() Here is an example of how it may be called passing in a string parameter: prompt(“please enter your PIN”);

  6. A side effect is the change to the internal (computer) or external environment (eg. output to display) that may be caused by running a function. Functions are often useful because of the side-effects they produce (as well as the values that they return). Note: A function that returns a value won’t necessarily have a side effect.

  7. An example of a function that produces a side effect is: prompt(); which displays a dialog box with the text displayed and allows the user to enter a value.
    Whilst an example of another function that produces a value is: Math.min(,); which returns the minimum number, either <number 1> or <number 2>
    E.g. Math.min(5, 3); returns 3.

  8. Control flow is the order in which the specific statements are executed in a programme. This by default is linearly (from top to bottom) but may programs have programming constructions such as loops and conditional operations that can change the order of execution of the statements, making it more complicated to follow the flow of control through the programme.

  9. Conditional execution is where some part of the code may or may not be executed.

  10. In Javascript the if keyword can be used to create conditional execution, specifically an if ‘expression’, whereby the statements following the if ‘expression’ will only be executed if the expression evaluates to true . Eg. if (2 > 6) console.log(“The first number is larger than the second”);
    // which in this case the console.log function will not be executed as the if expression will evaluate to false. The program will continue to run any further programme statements that follow after it.

3 Likes

1/ An expression is a fregment of code that results in a value.
2/ A binding is a value / string which is set to a variable.
3/ An environment is a collection of bindings that exist at a given time.
4/ A function is a wrapped section that performs a task.
5/ console.log (“medium”);
6/ A side effect is a function that produces an expression that returns that value.
7/ console.log. (10 * 20 "); produces a value alert / prompt (“enter name”);
8/ Its the direction of the execution of the code in javascript that goes from top down.
9/ It is when the programme based on the condition decides what to do.
10/ if else

2 Likes
  1. What is an expression?
    A fragment of code that produces a value

  2. What is a binding?
    Use to catch and hold values, typically called binaries or variables.

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

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

  5. Give an example of a function.
    Console.log(prompt(“take my money”));

  6. What is a side effect?
    Changes that occurs as a result of a statement or execution of a statement which could lead to a change in the internal state of the machine in a way that will affect the next statement after it.

  7. Give an example of a function that produces a side effect and another function that produces a value.
    alert("hello world);
    console.log(prompt(“take action”));

The above functions produces side effect

var a=10
var b= 5
console.log(a+b)

The above function produces value

  1. What is control flow?
    Execution of program in a story-like manner from top to down by Javascript is known as the control flow.

  2. What is conditional execution?
    Conditional execution uses the keyword “if” and “else” when certain conditions hold as not all programming are straight roads execution

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

2 Likes
  1. What is an expression? A Fragment of code that produces a value
  2. What is a binding? It is used to catch and hold values
  3. What is an environment? A Collection of bindings and their values
  4. What is a function? A Piece of program, wrapped in a value
  5. Give an example of a function. Prompt(“Enter Name”);
  6. What is a side effect? A side-effect is when an operation has an effect on a variable/object that is outside the intended usage.
  7. Give an example of a function that produces a side effect and another function that produces a value.

prompt(“hi”);

console.log(power(2, 10));

// → 1024

  1. What is control flow? The order in witch statements are executed.
  2. What is conditional execution? When code gets executed only when certain conditions are met
  3. What kind of keyword do you need to use to invoke conditional execution? If, else, else if
2 Likes