Binding, Functions and Control Flow - Reading Assignment

  1. an expression is a computation of values.

  2. A binding is a process in which a variable is assigned to a specific type of object.

  3. An environment is a collection of variables and values that exist at a given time.

  4. A function is a unit of code that takes inputs and produces a concrete output of truth.

  5. f(x)=x+3

6.A side effect is one of the results of a function.

7.an alert produces a side effect and an expression produces a value.

  1. Control flow is computation during the execution of programs or applications.

  2. a conditional execution is the use of boolean expressions to confirm a true or false choice resulting in 1 of 2 related outcomes.

  3. If

1 Like
  1. What is an expression?
    An expression is any arrangement of symbols, that produces a value. It can be for example a number, string, or a result of complex arrangement of values, operators and expressions.

  2. What is binding?
    Binding is a variable, that is declared with the keyword let. It can be tagged to any value. It can also be changed to point to another value at any time. Keywords var and const are also used to define bindings. A binding defined with const can’t be changed.

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

  4. What is a function?
    Function is a set of statements that performs some task or calculates and returns a value. Function is also a value.

  5. Give an example of a function.
    console.log(“hello”);

  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.
    console.log(100*200), Math.pow(8,3)

  8. What is control flow?
    When a program contains several statements, they are executed in certain order. This is called control flow.

  9. What is conditional execution?
    Parts of the code might be executed only if a specific set of conditions are true. In other words, parts of the code are executed conditionally.

  10. What kind of keyword do you need to use to invoke conditional execution?
    It can be done with keywords if, else if, else. There are also other ways to do it. The conditions in loop statements determine how many times the code is executed. Also switch, case can be used.

1 Like
  1. What is an expression?
    A piece of code the returns a value.

  2. What is a binding?
    Sometimes called a variable it holds a value.

  3. What is an environment?
    A collection of bindings and there values at any time.

  4. What is a function?
    A piece of program wraped in a value

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

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

  7. Give an example of a function that produces a side effect and another function that produces a value.
    console.log(Math.min(62,97)+100);
    // -> 162

  8. What is control flow?
    When a program has more than one statement they are executed from top to bottom

  9. What is conditional execution?
    When we want a program to branch in different directions depending on the situation

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

1 Like
  1. An expression can be either a value or a mathematical operation or function of one or multiple values. It can also be an expression of an expression.

  2. A binding is how a program creates and maintains an internal state, with clearly defined variables. The functions “let” and “var” can be used for that. However, the internal state can be changed again in the future, so the binding itself is not always static. It works more like a tether, tethering it to a specific value. On the other hand, using “const” creates a constant variable that stays the same forever.

  3. An environment is a collection of the bindings and values inside the program, maintaining its internal state. A program always starts out with things like functions and syntax needed to run itself. The programmer can define more bindings in the program as needed.

  4. A fuction is a program either already provided in the default environment, or one that can be defined by the programmer. It makes doing a complex task easier as the operations of the function are already clearly defined and ready to use.

  5. prompt(), console.log(), alert()

  6. A side effect is an expression or function that modifies the state of something outside its scope, such as one function redefining a variable outside itself, or the program giving an output into the webpage

  7. alert() produces a side effect of the user seeing an alert in the browser. Math.max() just produces a value

  8. Control flow is how statements are executed in a program, such as if statements. The order is from top to bottom.

  9. Conditional execution is where there are multiple branches, and the program takes the proper branch based on the situation.

  10. if, else if, else

1 Like

1)A fragment of code that produces a value is called an expression.
2)a declaration of a value. To catch and hold values, JavaScript provides a thing called a
binding or variable. ten = 10, x = 5 redeclaration is possible… ten = 11
3) the collection of all given bindings and their values represent the environment
4) function is a type of value, executing a function means applying a function
function(“argument”); one can expect that sth. will happen when calling a function (eg pop-up?)
5) alert(Math.min(5,9));
//pop up–>5
6) Showing a dialog box or writing text to the screen is a side effect.
7)

let num = Number(prompt(“Pick a number”)); //side effect: prompt --> popup
if (num < 10) {
console.log(“Small”);
} else if (num < 100) {
console.log(“Medium”);
} else {
console.log(“Large”);
}

alert(Math.min(5,9)); // both: side-effect due to alert & produced value 5
//–>5

  1. If a program contains multiple statements, the statements will be processed straight from top to bottom (process flow):

let a = 6, b = 5;

let a = 5;

console.log(a+b);
//–> 10 (not 11)

If a program has decision branches like if/else the process flow is branched this is called conditional execution.
10) if

1 Like
  1. A fragment of code that produces a value . Every value that is written literally (such as 99 or “CryptoMillionaire”) is an expression.
  2. A placeholder to catch and hold values. Names of bindings can be any meaningful words to describe the value, with the exception of keywords that are reserved like ‘let’, ‘var’, ‘const’ and other words that would create a syntax error should one try to use them as the name of the binding. Bindings do not contain values, they catch/grasp/retrieve them.
  3. The collection of bindings and their values that exist at a given time is called the environment
  4. A function is a piece of program wrapped in a value. Such values can be applied in order to run the wrapped program.
  5. prompt(“Enter passcode”);
  6. Showing a dialog box or writing text to the screen is a side effect
  7. the function Math.max takes any amount of number arguments and gives back the greatest.

console.log(Math.max(2, 4));
// → 4
8. The order in which statements, instructions, or functions of a program are executed.
9. controls whether or not the core will execute an instruction.
10. It’s created using the ‘If’ keyword.

1 Like

Nice, detailed answers, @jpc :ok_hand:

Just a couple of additional observations regarding conditional execution:

That’s right :+1: … and I would also add that the decision about which “branch” to take is based on whether a condition (a Boolean expression) evaluates to true or false . This is key to how conditional execution operates within a program.

Just to be clear… you are right that if (and else) are the keywords used; however they are not “Boolean operators” — in fact there is no such thing as a “Boolean operator” in JavaScript. The if and else keywords declare that a conditional statement follows. An if statement has a conditional expression enclosed in parentheses directly after the if keyword and before the code block wrapped in curly brackets. This conditional expression is also known as a Boolean expression because it evaluates to one of the two Boolean values true or false. Boolean expressions commonly are Comparison operators and logical operators are commonly used in conditional/Boolean expressions.

… again, to clarify… you can have:

  • individual “chains” with more than 2 branches — in which case the else if (or multiple else if') keywords are often used after the intial if and final else statements;
  • if...else pairs (or longer if...else if ....else chains) nested within outer ones.
1 Like

Hi @ashishc,

Good answers :ok_hand:

Just a couple of additional observations:

In this piece of code, Math.min(2, 4)  is a function that produces a value (2), and the console.log() that it’s wrapped in is a function that produces a side effect, the side effect being printing the value produced by the inner function (2) + 100 (102) to the console.

We need to be more specific here e.g.

Conditional execution is where the program’s control flow takes only one of two alternative paths. The decision of which path to take is based on whether a condition (a Boolean expression) evaluates to true or false (i.e. whether the the condition is met or not). Where a series of consecutive conditions are used, only one of several alternative paths will end up being executed.

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

  • What is a binding?
    Also known as a Variable, they are used To catch and hold values in memory.

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

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

  • Give an example of a function.
    function countApples = (3+1);

  • What is a side effect?
    Showing a dialog box or writing text to the screen

  • Give an example of a function that produces a side effect and another function that produces a value.
    prompt(“Enter passcode”);
    function countApples = (3+1);

  • What is control flow?
    When there is more than one statement it uses control flow to go top to bottom

  • What is conditional execution?
    Taking the proper branch depending on the situation or inputs given

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

created with the “If” keyword

1 Like
  1. An expression is a fragment of code that produces a value.
  2. Binding is a variable ie a container for a value.
  3. An environment is the current grouping of values in memory.
  4. A function is a piece of program wrapped in a value.
  5. a = b+c;
  6. A side effect is something extra a function does other than return a value.
  7. a) console.log(“hi”); b) a = 1 +2;
  8. Flow control is when we use conditional statements to decide which code to execute.
  9. A conditional execution is execution that occurs after a conditional statement is true.
  10. Keywords such as if/else are used to invoke conditional execution.
1 Like
  1. a fragment of code that produces a value.
  2. binding gives an element a value so it can be stored.
    3.a collection of bindings and their given values that exist at a given time.
    4.a piece of program wrapped in a value.
    5.prompt
  3. changeing statement that could change the internal state of the machine and the statements that come after it.
  4. prompt or log are examples of functions that give a side effect.
  5. control flow of a program is when the program you have more than one statement and it is the path taken to execute the statements in the programme, read like a story.
  6. It is a logical test that determines which path to follow , if or else , true or false
  7. If and else
1 Like
  1. Expression is a piece of code which produces a value.
  2. Binding is a storing of variable inside a memory.
  3. The environment is a collection of variables and their values inside a program at a given time.
  4. A function is a piece of program wrapped in a value, which if it has given an argument/s, will produce another value/s.
  5. Math.max, Math.min, alert…
  6. Side effect is a result of a previous statement which effects the statement after it.
  7. Alert is an example of a side effect function because it creates a prompt window and Math.min is an example of a function which creates a value.
  8. It is the way how statements are executed in a program – from top to bottom.
  9. It is the alternative way of executing the statements, in this case based on Boolean value true/false.
  10. To invoke the conditional execution in JavaScript we use keyword – if.
1 Like

Binding, Functions and Control Flow-Reading Assignment



  1. What is an expression?

  2. To use an analogy in the Javascript language an expression is akin to a sentence fragment. It's any piece of code that produces a value. ANY PIECE

  3. What is binding?

  4. A binding is when you attach a specific value to a variable. Ex. Let 3 = 1, 7 = 5;
    Console.log(7 / 3);
    // ->5

  5. What is an environment?

  6. An environment is the collection of bindings that exist at any given time within the machine.

  7. What is a function?

  8. A function is a section of code wrapped within an expression.

  9. Give an example of a function.


  10. a classic and widely used function is to invoke console.log( insert expression/variable?here)

  11. What is a side effect?

  12. when and only when a "statement" effects the "world" it is classified as a "side effect"

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


  14. console.log (8 * 8);
    // -> 64; is an example of a function producing a value.
    prompt (hire the guy who wrote this); changes the world and as such produces a side effect (of stacking massive sats fyi😉)

  15. what is "control flow"?

  16. to put it simply control flow is the way the functions are executed.

  17. What is conditional execution?

  18. it is a way to add logic to a program. Now will only execute a function when the proper input is detected.This is characterized generally by an "if" though "else" and "switch" are also effective. This allows your program to change or "loop"

  19. what kind of keyword do you need to invoke conditional execution?

    adding "if" "switch" or "else" will call a conditional execution
1 Like

Hi @Adam1,

Q3, 4, 9 & 10 :ok_hand:

Let’s have closer look at the other questions:

…it can be, but an expression can also just be a single value. An expression is any piece of code that evaluates to (produces) a value.

…not really… binding and variable are two alternative terms for the same thing: any value or expression which has been assigned to a name (effectively labelled) in order for it to be stored in the computer’s memory, and then accessed and reused by the program whenever required.

This is a good mathematical representation of a function. An example specific to JavaScript could be either of the following:

alert("This is an alert!");

function f(x) {
   return x + 3;
}

Yes… but all functions produce results (outputs). A side effect is a specific type of output — an action which occurs externally (outside of the program).

Yes…the alert() function produces a side effect, and the side effect is the alert pop-up that appears in the browser when this function is executed.

…while this is true, the question asks for an example of a function that produces a value. An example would be:

function f(x) {
   return x + 3;
}

…more specifically, it refers to the order in which individual pieces of code (i.e. statements, functions, loops, variables etc.) are executed or evaluated. Control flow enables the computer to correctly decide which path to take through a program, from starting at the top, to finishing at the bottom.

I hope this makes certain aspects clearer, and gives you a better understanding of this section.

1 Like

Nice answers @hoolie :ok_hand:

That’s right :+1: … and I would also add that the decision about which “branch” to take is based on whether a condition (a Boolean expression) evaluates to true or false . This is key to how conditional execution operates within a program.

1 Like

Excellent answers, with some nice detail, @Mujtahid_Haque! :+1:
I can see you’ve put a lot of thought and effort into this assignment.

That’s right :+1: … and I would also add that the decision about which “branch” to take is based on whether conditions (Boolean expressions) evaluate to true or false . This is key to how conditional execution operates within a program.

1 Like

Hi @Steffen,

Nice answers :ok_hand:

Yes … and I would also add that the decision about which “branch” to take is based on whether conditions (Boolean expressions) evaluate to true or false . This is key to how conditional execution operates within a program.

1 Like

Nice answers @Long :ok_hand:

Just to clarify a couple of points…

Yes… and in this piece of code, Math.max(2, 4) is a function that produces a value (4), and the console.log() that it’s wrapped in is a function that produces a side effect, the side effect being printing the value produced by the inner function (4) to the console.

That’s only really half the story… conditional execution is more about controlling which of two or more alternative branches of code will be executed next. The decision about which “branch” to take is based on whether conditions (Boolean expressions) evaluate to true or false (i.e whether they are met or not).

1 Like

Hi @Wevlin,

Mostly good answers :ok_hand:

Just a couple of clarifications…

This is a strange cross between a binding and a function :upside_down_face:
A function in JavaScript can be declared and then called (executed) as follows:

function countApples(firstTree, secondTree) {
   return firstTree + secondTree;
}

let totalApples = countApples(30, 10);
console.log(totalApples);   // => 40

The first 3 lines of code (the actual function) would also be the example of a function that produces a value for your answer to Q7.

Yes … and I would add that the decision about which “branch” to take is based on whether a condition (a Boolean expression) evaluates to true or false . This is key to how conditional execution operates within a program.

What is an expression?

An expression can be an integer, string, any fragment of code which produces a value. an expression between parenthesis or a binary operator between 2 expressions.

What is a binding?

Bindings are synonymous with variables. They are simply a means to assign and store values which can be easily recalled later on.

What is an environment?

An environment is a collection of bindings and their current values. The environment is also a collection of settings related to the machine and even the browser has its own environment and settings such as window state and size for example.

What is a function?

A function is a small program which runs inside a larger program and can return values or make changes as the main program runs. They can perform tasks such as simply adding two numbers together and returning the value or make changes to the running state of the environment. I like to think of them as reusable chunks of code.

Give an example of a function.

The example function i will give will add 2 numbers together and return the result

function addMe(val1, val2) {
    return val1 + val2
}

What is a side effect?

A side effect is something that happens other than producing a value such as moving an object on screen or opening an alert box.

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

  1. Function to produce value
    Math.floor{Math.random() * 100) + 1
  2. Function to produce a sideeffect.
    alert(Math.floor(Math.random() * 100) +1)

What is control flow?

Control flow relates to the execution of statements in a program. The flow travels from top to bottom so the first statement on the top of the page executes first and last statement at bottom of page executes last.

What is conditional execution?

Conditional execution is a way of isolating snippets of code within the control flow and only executing the contained code when a particular condition is met.

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

The keywords if, else if and else are used to control conditional branching for example:
if (condition) {
do this;
} else if {
do this;
} else {
do this;
}

1 Like